积极答复者
error LNK 2019无法解析外部符号? 求解

问题
-
程序很简单,但是就是编译通过不了,本人是初学者,请教各位大神
//Plorg.h
#ifndef PLORG_H_
#define PLORG_H_
class Plorg{
private:
char plorgname[20];
unsigned int CI;
public:
Plorg();
Plorg(char name[], int valCi);
void showPlorg();
void setCI(int val);
};
#endif//Plorg.cpp
#include"Plorg.h"
#include<iostream>
Plorg::Plorg()
{
CI = 50;
char temp[] = "Plorg";
int i = 0;
for (i = 0; i < temp[i]; i++)
{
plorgname[i] = temp[i];
}
plorgname[i] = '\0';
}
Plorg::Plorg(char name[], int val_CI)
{
CI = val_CI;
int i = 0;
for (i = 0; name[i]; i++)
{
plorgname[i] = name[i];
}
plorgname[i] = '\0';
}
void Plorg::showPlorg()
{
using std::cout;
using std::endl;
cout << "Name: " << plorgname << endl;
cout << "CI: " << CI << endl;
}
void Plorg::setCI(int val)
{
CI = val;
}//main.cpp
int main()
{
Plorg one;
Plorg two("Apple", 99);
one.showPlorg();
two.showPlorg();
one = Plorg("Canon", 98);
two.setCI(78);
two.showPlorg();
one.showPlorg();
return 0;
}error信息:
错误 1 error LNK2019: 无法解析的外部符号 "public: __thiscall Plorg::Plorg(void)" (??0Plorg@@QAE@XZ),该符号在函数 _main 中被引用 D:\代码\Visual Stadio 2013\C++ primer plus\10.11.7\main.obj 10.11.7
错误 2 error LNK2019: 无法解析的外部符号 "public: __thiscall Plorg::Plorg(char * const,int)" (??0Plorg@@QAE@QADH@Z),该符号在函数 _main 中被引用 D:\代码\Visual Stadio 2013\C++ primer plus\10.11.7\main.obj 10.11.7
错误 3 error LNK2019: 无法解析的外部符号 "public: void __thiscall Plorg::showPlorg(void)" (?showPlorg@Plorg@@QAEXXZ),该符号在函数 _main 中被引用 D:\代码\Visual Stadio 2013\C++ primer plus\10.11.7\main.obj 10.11.7
错误 4 error LNK2019: 无法解析的外部符号 "public: void __thiscall Plorg::setCI(int)" (?setCI@Plorg@@QAEXH@Z),该符号在函数 _main 中被引用 D:\代码\Visual Stadio 2013\C++ primer plus\10.11.7\main.obj 10.11.7
但是如果把类和在main.cpp里面就没有问题,对Vc++,还不够熟悉,希望各位解答
答案
-
如果Plorg类不在main.cpp里面,则需要在main.cpp里面引用Plorg类的头文件,把下面代码添加到main.cpp里面即可
#include"Plorg.h"
- 已标记为答案 May Wang - MSFT 2014年5月2日 8:43
-
您这里报的是链接错误,您的Plorg.cpp是不是没有被包含进工程中?在VS的Solution Explorer标签右键选在Add/Exist Item...将您的Plorg.cpp加入工程中去。
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
- 已标记为答案 May Wang - MSFT 2014年5月2日 8:43
全部回复
-
如果Plorg类不在main.cpp里面,则需要在main.cpp里面引用Plorg类的头文件,把下面代码添加到main.cpp里面即可
#include"Plorg.h"
- 已标记为答案 May Wang - MSFT 2014年5月2日 8:43
-
您这里报的是链接错误,您的Plorg.cpp是不是没有被包含进工程中?在VS的Solution Explorer标签右键选在Add/Exist Item...将您的Plorg.cpp加入工程中去。
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
- 已标记为答案 May Wang - MSFT 2014年5月2日 8:43