2014-12-11 84 views
0

大家好,今天每個人都有我的代碼。我創建了一個方形的圓形和矩形的計算區域。具有基礎類的形狀。如果UML已經作爲具有public area()的抽象類來構造:double,getName():string和getDimensions:字符串,由具有受保護高度和寬度的形狀派生的矩形和公共矩形(h:double,w:雙),然後從矩形派生出一個只有公共廣場(h:double)的方形,最後是一個由具有私有半徑的形狀和一個公共圓(r:double)派生的圓。 到目前爲止,在我的代碼中得到了很多,但在我的shape.cpp文件中,第10行發現了一個錯誤,指出shape.cpp:10:error:隱式聲明的'constexpr shape :: shape'的定義' shape: :形狀()隱式聲明的C++編譯器錯誤定義

這裏是我的完整代碼的鏈接:https://gist.github.com/anonymous/0eedd7719a34655488fb

shape.cpp文件:

#include "shape.h" 
#include "circle.h" 
#include "rectangle.h" 
#include "square.h" 
#include <QDebug> 
#include <QString> 
#include <iostream> 
using namespace std; 

shape::shape() 
{ 

}; 

您的幫助表示讚賞

+0

您還沒有在'shape'類定義中聲明'shape'構造函數。 – user657267 2014-12-11 01:46:29

+0

整個rectangle.cpp是重新聲明它的頭部? – AlexanderVX 2014-12-11 01:52:05

+0

謝謝你們,我做了推薦的更改,現在我得到一個錯誤,說shape.cpp – ana 2014-12-11 02:15:43

回答

3

您需要添加shape()常量ructor到類的聲明是這樣的:

#ifndef SHAPE_H 
#define SHAPE_H 
#include <QString> 
#include <QDebug> 

using namespace std; 

class shape 
{ 
public: 

    shape(); 
    virtual double area()=0; 

    virtual QString getName()=0; 
    virtual QString getDimensions()=0; 

    virtual~shape(){} 

}; 
#endif 

然後,您可以創建shape.cpp的定義是這樣的:

shape::shape() 
{ 

} 

結尾沒有分號。

+0

的第10行重新定義shape :: shape,所以我繼續前進並刪除上面的分號,然後我更正了我的shape.h,以便現在讀取如下 – ana 2014-12-11 02:00:34