我只想检查以便从父类继承构造函数,这是通过使用对象组合来完成它的正确方法吗?用于继承的C++构造函数
我得到这个错误,他们都指的是我的构造函数。
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;
}
square.h
新的脚本class Square:public ShapeTwoD
{
private:
int xVal,yVal;
int newlength, newbreath;
double area;
public:
Square();
Square(string, bool, int, int);
};
square.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;
}
有什么你试过了吗?例如,您可以在构造函数中打印语句并确定它们的构建顺序。 – carlosdc
看起来不错。在StackExchange网络中有一个[site](http://codereview.stackexchange.com/)用于代码审查,它可能更适合那里。 – nvoigt
好吧,看来你已经编辑了你的问题。你如何宣布这些课程? – deepmax