我只想检查以便从父类继承构造函数,这是使用对象组合的正确方法吗?
我得到了这个错误,它们都指的是我的构造函数。
C:\Users\user\AppData\Local\Temp\cc0CYtVR.o:SquareImp.cpp:(.text+0x16): undefine
d reference to `vtable for Square'
C:\Users\user\AppData\Local\Temp\cc0CYtVR.o:SquareImp.cpp:(.text+0x79): undefine
d reference to `vtable for Square'
C:\Users\user\AppData\Local\Temp\cc0CYtVR.o:SquareImp.cpp:(.text$_ZN6SquareD1Ev[
Square::~Square()]+0xb): undefined reference to `vtable for Square'
collect2: ld returned 1 exit status
抱歉,这是我的新脚本,因为我已经尝试重写它们
ShapeTwoD.h
class ShapeTwoD
{
protected:
string name, warpSpace;
bool containsWarpSpace;
int xCord, yCord, length, breath;
public:
//constructor
ShapeTwoD();
ShapeTwoD(string, bool);
};
ShapeTwoD.cpp
ShapeTwoD::ShapeTwoD()
{
string name = "";
bool containsWarpSpace = true;
}
ShapeTwoD::ShapeTwoD(string ShapeName, bool warpspace)
{
name = ShapeName;
containsWarpSpace = true;
}
平方.h
class Square:public ShapeTwoD
{
private:
int xVal,yVal;
int newlength, newbreath;
double area;
public:
Square();
Square(string, bool, int, int);
};
正方形.cpp
Square::Square()
{
xVal = 0;
yVal = 0;
}
Square::Square(string ShapeName, bool warpspace, int xval, int yval):ShapeTwoD(ShapeName, warpspace), xVal(xval), yVal(yval)
{
xVal = xval;
YVal = yval;
cout << "test test" << endl;
}
int main()
{
Square square;
cout << "hello world" << endl;
}