大家好,最近在努力学习C++,但是遇见了一些问题,很希望懂的人士帮我解答下,这对于你们很简单吧,嘿嘿,谢谢了
代码如下:
#include<iostream>
using namespace std;
class Box{
public:
double length;
double heigth;
double width;
int d;
Box();
Box(double length1,double heigth1,double width1){
length=length1;
heigth=heigth1;
width=width1;
}
double volume(){
return length*heigth*width;
}
};//要有分号哦!
int main(){
Box firstBox(2.0,4.0,6.0);
firstBox.d=2;
cout<<endl
<<firstBox.length<<"\n"
<<firstBox.heigth<<"\n"
<<firstBox.width<<"\n"
<<firstBox.d
<<endl;
cout<<firstBox.volume();
Box smallBox;
smallBox.length=10.0;
smallBox.heigth=5.0;
smallBox.width=4.0;
cout<<endl;
cout<<smallBox.length<<"\n"
<<smallBox.heigth<<"\n"
<<smallBox.width<<"\n"
<<smallBox.volume()
<<endl;
return 0;
}
在Dev_C++5.6.1上编译的,出现了如下:
C:\Users\ADMINI~1\AppData\Local\Temp\ccgxkOkf.o lei1.cpp:(.text+0x10f): undefined reference to `Box::Box()'
D:\Dev-Cpp\大二C\collect2.exe [Error] ld returned 1 exit status
我在百度上搜了很多,但很不理解,希望各位帮忙解答下。谢谢了