| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1378 人关注过本帖
标题:2010,运行不了,麻烦看下。
只看楼主 加入收藏
cellphone
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2010-11-16
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:5 
2010,运行不了,麻烦看下。
新建一个项目encrypt,把相应的代码utility.h,node.h,lk_list.h,string.h复制到文件中,在头文件中建立一个encrypt.h,进行类的声明,代码如下:
#include"lk_list.h"
#include"string.h"


class Encrypt
{
private:
    String letters;
    String map;
public:
    Encrypt();
    virtual ~Encrypt();
    String EnCode(const String &str);
    String DeCode(const String &str);
};
然后做源文件中建立encrypt.cpp和main.cpp,代码如下:
encrypt.h文件:
#include"encrypt.h"


Encrypt::~Encrypt()
{
}
Encrypt::Encrypt()
{
    letters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    map="NgzQTCobmUHelkPdAwxfYIvrsJGnZqtcOBMuhELKpaDWXFyiVRjS";
}
String Encrypt::EnCode(const String &str)
{
    LinkList<char> lk_tem;
    for(int i=0;i<str.Length();i++)
    {
        int pos;
        for(pos=0;pos<52;pos++)
        {
            if
                (str[i]==letters[pos])
            {
                lk_tem.Insert(lk_tem.Length()+1,map[pos]);
                break;
            }
        }
        if
            (pos==52)
        {
            lk_tem.Insert(lk_tem.Length()+1,str[i]);
        }
    }
    String result(lk_tem);
    return result;
}
String Encrypt::DeCode(const String &str)
{
    LinkList<char> lk_tem;
    for(int i=0;i<str.Length();i++)
    {
        int pos;
        for(pos=0;pos<52;pos++)
        {
            if
                (str[i]==map[pos])
            {
                lk_tem.Insert(lk_tem.Length()+1,letters[pos]);
                break;
            }
        }
        if
            (pos==52)
        {
            lk_tem.Insert(lk_tem.Length()+1,str[i]);
        }
    }
    String result(lk_tem);
    return result;
}
main.h文件:
#include"encrypt.h"
#include"utility.h"

int main(void)
{
    int select=1;
    char source[256],destination[256];
    Encrypt objEncrypt;
    while(select!=3)
    {
        cout<<"请选择"<<endl;
        cout<<"1.加密--将输入的文本进行加密之后输出"<<endl;
        cout<<"2.解密--将输入的文本进行解密之后输出"<<endl;
        cout<<"3.退出--退出当前程序"<<endl;
        cin>>select;
        switch(select)
        {
        case 1:
            cout<<"请输入文本"<<endl;
            cin>>source;
            strcpy(destination,objEncrypt.EnCode(source).CStr());
            cout<<"加密串:"<<destination<<endl<<endl;
            break;
        case 2:
            cout<<"请输入文本"<<endl;
            cin>>source;
            strcpy(destination,objEncrypt.DeCode(source).CStr());
            cout<<"解密串:"<<destination<<endl<<endl;
            break;
        }
    }
    system("PAUSE");
    return 0;
}
编译成功,但是运行不了。错误如下:

1>main.obj : error LNK2005: "char __cdecl GetChar(class std::basic_istream<char,struct std::char_traits<char> > &)" (?GetChar@@YADAAV?$basic_istream@DU?$char_traits@D@std@@@std@@@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "bool __cdecl UserSaysYes(void)" (?UserSaysYes@@YA_NXZ) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "public: __thiscall Timer::Timer(void)" (??0Timer@@QAE@XZ) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "public: double __thiscall Timer::ElapsedTime(void)" (?ElapsedTime@Timer@@QAENXZ) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "public: void __thiscall Timer::Reset(void)" (?Reset@Timer@@QAEXXZ) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "public: __thiscall Error::Error(char * const)" (??0Error@@QAE@QAD@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "public: void __thiscall Error::Show(void)const " (?Show@Error@@QBEXXZ) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "void __cdecl SetRandSeed(void)" (?SetRandSeed@@YAXXZ) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "int __cdecl GetRand(int)" (?GetRand@@YAHH@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "int __cdecl GetRand(void)" (?GetRand@@YAHXZ) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "int __cdecl GetPoissionRand(double)" (?GetPoissionRand@@YAHN@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "public: __thiscall String::String(void)" (??0String@@QAE@XZ) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "public: virtual __thiscall String::~String(void)" (??1String@@UAE@XZ) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "public: __thiscall String::String(class String const &)" (??0String@@QAE@ABV0@@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "public: __thiscall String::String(char const *)" (??0String@@QAE@PBD@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "public: __thiscall String::String(class LinkList<char> &)" (??0String@@QAE@AAV?$LinkList@D@@@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "public: int __thiscall String::Length(void)const " (?Length@String@@QBEHXZ) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "public: bool __thiscall String::Empty(void)const " (?Empty@String@@QBE_NXZ) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "public: class String & __thiscall String::operator=(class String const &)" (??4String@@QAEAAV0@ABV0@@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "public: char const * __thiscall String::CStr(void)const " (?CStr@String@@QBEPBDXZ) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "public: char & __thiscall String::operator[](int)const " (??AString@@QBEAADH@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "void __cdecl Concat(class String &,class String const &)" (?Concat@@YAXAAVString@@ABV1@@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "class String __cdecl Read(class std::basic_istream<char,struct std::char_traits<char> > &)" (?Read@@YA?AVString@@AAV?$basic_istream@DU?$char_traits@D@std@@@std@@@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "class String __cdecl Read(class std::basic_istream<char,struct std::char_traits<char> > &,char &)" (?Read@@YA?AVString@@AAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAD@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "void __cdecl Write(class String const &)" (?Write@@YAXABVString@@@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "void __cdecl Copy(class String &,class String const &)" (?Copy@@YAXAAVString@@ABV1@@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "void __cdecl Copy(class String &,class String const &,int)" (?Copy@@YAXAAVString@@ABV1@H@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "int __cdecl Index(class String const &,class String const &,int)" (?Index@@YAHABVString@@0H@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "class String __cdecl SubString(class String const &,int,int)" (?SubString@@YA?AVString@@ABV1@HH@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "bool __cdecl operator==(class String const &,class String const &)" (??8@YA_NABVString@@0@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "bool __cdecl operator<(class String const &,class String const &)" (??M@YA_NABVString@@0@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "bool __cdecl operator>(class String const &,class String const &)" (??O@YA_NABVString@@0@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "bool __cdecl operator<=(class String const &,class String const &)" (??N@YA_NABVString@@0@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "bool __cdecl operator>=(class String const &,class String const &)" (??P@YA_NABVString@@0@Z) 已经在 encrypt.obj 中定义
1>main.obj : error LNK2005: "bool __cdecl operator!=(class String const &,class String const &)" (??9@YA_NABVString@@0@Z) 已经在 encrypt.obj 中定义
1>E:\2010实验\encrypt\Debug\encrypt.exe : fatal error LNK1169: 找到一个或多个多重定义的符号

都不是语法错误,麻烦看看。
而假如把函数的定义与声明放在同一个头文件的话就运行成功,为什么呢?

[ 本帖最后由 cellphone 于 2010-11-18 21:48 编辑 ]
搜索更多相关主题的帖子: 运行 麻烦 
2010-11-17 11:45
玩出来的代码
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:河南新乡
等 级:贵宾
威 望:11
帖 子:742
专家分:2989
注 册:2009-10-12
收藏
得分:10 
文件重复包含的问题,自己看吧。

离恨恰如春草,更行更远还生。
2010-11-17 17:54
cellphone
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2010-11-16
收藏
得分:0 
回复 2楼 玩出来的代码
不懂意思,文件重复,不知道在哪里出现这样的问题。
2010-11-17 22:43
南国利剑
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:29
帖 子:1165
专家分:3536
注 册:2010-4-12
收藏
得分:10 
标识符重定义了
应该就是头文件重复包含引起的。

南国利剑
2010-11-18 18:52
xin310923
Rank: 5Rank: 5
等 级:职业侠客
威 望:1
帖 子:203
专家分:325
注 册:2009-12-22
收藏
得分:0 
回复 4楼 南国利剑
冯,你2010的能编译通过吗。
2010-11-18 19:17
cellphone
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2010-11-16
收藏
得分:0 
回复 4楼 南国利剑
头文件的重复包含,是哪个头文件呢?utility.h肯定不是。然后string.h也不是,而encrypt.h如果不包含的话,那下面的那些就没有意义了。
2010-11-18 21:45
快速回复:2010,运行不了,麻烦看下。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013156 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved