我只想檢查以便從父類繼承構造函數,這是通過使用對象組合來完成它的正確方法嗎?用於繼承的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