2016-05-02 18 views
1

エラーの結果として使用されている.cppファイルと.hファイルはすべてここにあります。彼らは私が以前に見て修正したエラーですが、私はなぜこれらのエラーが出ているのか分からず、コードの正しい構文を作っていません。単純なコンパイルエラーですが意味がありません

shape.h

#ifndef SHAPE_H 
#define SHAPE_H 
#include <iostream> 
#include <math.h> 
#include <cmath> 
#include <cstring> 
#include <string> 
#include <algorithm> 
#include <iomanip> 
#include <stdlib.h> 

using std::cout; using std::cerr; using std::endl; 
using std::string; 
    class Shape{ 
     public: 
    Shape(const string&) { } //default constructor 
    virtual void print() const; 
    virtual double get_area() const; 
    virtual ~Shape(); 
     private: 
    string color; 
    }; 
#endif 

shape.cpp

#include "shape.h" 
using std::cout; using std::cerr; using std::endl; 
using std::string; 
void Shape::print() const{ 
cout << color << endl; } 
Shape::Shape(const string& color1):color(color1) 
{/*color = color1;*/ } 
Shape::~Shape() 
{ } 

circle.h

#ifndef CIRCLE_H 
#define CIRCLE_H 
#include <iostream> 
#include <math.h> 
#include <cmath> 
#include <cstring> 
#include <string> 
#include <algorithm> 
#include <iomanip> 
#include <stdlib.h> 
#include <vector> 
#include "shape.h" 
using namespace std; 
using std::cout; using std::cerr; using std::endl; 
using std::string; using std::vector; 
class Circle : public Shape{ 
    public: 
    Circle(const string& , int); 
virtual void print() const; 
virtual double get_area() const; 
    private: 
int radius; 
}; 
#endif 

circle.cpp

#include "circle.h" 
using std::cout; using std::cerr; using std::endl; 
using std::string; 
Circle::Circle(const string& color1,int newRadius):Shape(color1),radius(newRadius) {} 

double Circle::get_area() const{ 
double area; 
area = M_PI * (pow(radius,2)); 
return area; 
} 

void Circle::print() const{ 
cout << "Circle: " << 
    << color << " circle, " 
    << "radius " << radius << ", " 
    << "area " << get_area() << endl; 
} 

のメイン

#include <iostream> 
#include "shape.h" 
#include "circle.h" 
#include <vector> 
using std::vector; using std::string; 
using namespace std; 
int main{ 

    vector<Shape *> shape1(1); 
    shape1[0] = new Circle("Green",20); 

/* 
for(int i = 0; i < arr; i++) 
i.print(); 

for(int i = 0; i < arr; i++) 
delete [] arr; 
*/ 
return 0; 

エラー:

assign9.cpp:9:17: error: expected primary-expression before ‘shape1’ 
vector<Shape *> shape1(1); 
       ^
assign9.cpp:9:17: error: expected ‘}’ before ‘shape1’ 
assign9.cpp:9:17: error: expected ‘,’ or ‘;’ before ‘shape1’ 
assign9.cpp:10:1: error: ‘shape1’ does not name a type 
shape1[0] = new Circle("Green",20); 
^ 
assign9.cpp:19:2: error: expected unqualified-id before ‘return’ 
    return 0; 
^
assign9.cpp:20:1: error: expected declaration before ‘}’ token 
} 

^ 

私も私のTAはそれを把握することができませんでした、これらのエラーは約来ているか理解していませんよ。私はフィードバックを感謝します。おかげで

+0

ヘッダーが含まれていないようです。 –

+0

'std;を使って'を追加しましたか?指令? std ::が指定されていない文字列とベクトルを使用している場合は、これを行う必要があります。 – CodeFuller

+3

Typo。あなたは 'class Circle'ではなく' class Cirlce'を持っています。 'l'と' c'は誤ってスワップされます。 –

答えて

4

サークルの代わりにCirlce。

std :: stringではなくstringです。形状(カラー1)、半径(newRadius){}

(すべてあなたを初期化します。

サイドノートで

、サークルのコンストラクタは、より良い サークル::サークル(のconst文字列&カラー1、INT newRadius)でなければなりません括弧ではなくコンストラクタで使用できます)。

+1

用語解説: "コンストラクタで"と言えば、より良い言葉遣いは "メンバーイニシャライザリスト"になります。 – user4581301

+0

サイドノートをありがとう、私は円の代わりにCirlceを修正しましたが、まったく同じエラーが発生します。 – Xenu

+0

私はそれを試しました。あなたのコードには多くのエラーがありますが、この同じエラーは発生しません。ファイルを保存するのを忘れたかもしれません。それでも問題が発生する場合は、最小限の例を作成してください(ファイルが1つ作成され、すべてのファイルが結合された後、ファイルをできるだけ小さくし、エラーの再現に不必要なものはすべて削除してください)。 – user31264

関連する問題