error LNK2019: 无法解析的外部符号
头文件Box.h
#ifndef BOX_H
#define BOX_H
class Box
{
public:
Box(double l=1.0,double w=1.0,double h=1.0);
double volume();
private:
double length;
double width;
double height;
};
#endif
Box.cpp文件
#include <iostream>
#include "Box.h"
using namespace std;
Box::Box(double l,double w,double h):length(l),width(w),height(h){
cout<<"constructor called!"<<endl;
if(length<=0.0)
length=1.0;
if(width<=0.0)
width=1.0;
if(height<=0.0)
height=1.0;
}
double Box::volume(){
return length*width*height;
}
Box_12.1.cpp 文件
#include<iostream>
#include "Box.h"
using namespace std;
int main(){
Box firstBox(2.2,1.1,0.5);
Box secondBox;
Box* pthirdBox=new Box(15.0,20.0,8.0);
cout<<"The volume of the first box is "
<<firstBox.volume()
<<endl;
cout<<"The volume of the second box is "
<<secondBox.volume()
<<endl;
cout<<"The volume of the third box is "
<<pthirdBox->volume()
<<endl;
delete pthirdBox;
return 0;
}
语法应该没问题,跑出来就报:
1>Box_12.1.obj : error LNK2019: 无法解析的外部符号 "public: double __thiscall Box::volume(void)" (?volume@Box@@QAENXZ),该符号在函数 _main 中被引用
1>Box_12.1.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall Box::Box(double,double,double)" (??0Box@@QAE@NNN@Z),该符号在函数 _main 中被引用
1>C:\Users\Administrator.WIN-VRV2JV05SFO\Documents\Visual Studio 2010\Projects\Example12.1\Debug\Example12.1.exe : fatal error LNK1120: 2 个无法解析的外部命令
在网上看了一下,有的说函数没有实现,但是在Box.cpp文件中已经实现了啊,有的说没有把.lib文件包含进来,但是也没有用到其他的库啊! 很费解,换其他程序也会这样报错。不知道是怎么回事?
#ifndef BOX_H
#define BOX_H
class Box
{
public:
Box(double l=1.0,double w=1.0,double h=1.0);
double volume();
private:
double length;
double width;
double height;
};
#endif
Box.cpp文件
#include <iostream>
#include "Box.h"
using namespace std;
Box::Box(double l,double w,double h):length(l),width(w),height(h){
cout<<"constructor called!"<<endl;
if(length<=0.0)
length=1.0;
if(width<=0.0)
width=1.0;
if(height<=0.0)
height=1.0;
}
double Box::volume(){
return length*width*height;
}
Box_12.1.cpp 文件
#include<iostream>
#include "Box.h"
using namespace std;
int main(){
Box firstBox(2.2,1.1,0.5);
Box secondBox;
Box* pthirdBox=new Box(15.0,20.0,8.0);
cout<<"The volume of the first box is "
<<firstBox.volume()
<<endl;
cout<<"The volume of the second box is "
<<secondBox.volume()
<<endl;
cout<<"The volume of the third box is "
<<pthirdBox->volume()
<<endl;
delete pthirdBox;
return 0;
}
语法应该没问题,跑出来就报:
1>Box_12.1.obj : error LNK2019: 无法解析的外部符号 "public: double __thiscall Box::volume(void)" (?volume@Box@@QAENXZ),该符号在函数 _main 中被引用
1>Box_12.1.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall Box::Box(double,double,double)" (??0Box@@QAE@NNN@Z),该符号在函数 _main 中被引用
1>C:\Users\Administrator.WIN-VRV2JV05SFO\Documents\Visual Studio 2010\Projects\Example12.1\Debug\Example12.1.exe : fatal error LNK1120: 2 个无法解析的外部命令
在网上看了一下,有的说函数没有实现,但是在Box.cpp文件中已经实现了啊,有的说没有把.lib文件包含进来,但是也没有用到其他的库啊! 很费解,换其他程序也会这样报错。不知道是怎么回事?
...全文
相关推荐
如何解决 error LNK2019 无法解析的外部符号,该符号在函数 中被引用
如何解决 error LNK2019 无法解析的外部符号,该符号在函数 中被引用
error LNK2019: 无法解析的外部符号 问题的解决办法
error LNK2019: 无法解析的外部符号 问题的解决办法,需要的朋友可以参考一下
解决error LNK2001 无法解析的外部符号 int __cdecl sprintf(
解决error LNK2001 无法解析的外部符号 int __cdecl sprintf(
vc报错解决办法 error LNK2019无法解析的外部符号,该符号在函数 中被引用
vc报错 error LNK2019无法解析的外部符号,该符号在函数 中被引用 的解决办法 解决办法不难,不想收这么高的费用,但是CSDN最低收费就是9.9元,我也没办法。而且我连1/3都分不到
error LNK1120和error lnk2001
对于编程人员在编译程序的时候经常会遇到error LNK1120和error lnk2001这问题,跟大家分享一下自己找到的资料,以及自己遇到的问题,希望对大家有帮助。


新手乐园
