2013-10-21 83 views
0

在編譯代碼的第一行時出現錯誤「xxx does not named a type」。 知道「poligono」是「triangulo」的基類,並且我寫了.cpp和.h 文件。錯誤:xxx沒有指定類型

我想知道我可以修復這個錯誤

#include <string.h> 
#include <iostream> 
#include "poligono.h" 
using namespace std; 
triangulo :: triangulo(int x1i, int x2i, int x3i, int y1i, int y2i, int y3i, string clasei, int ancho, int alto, int puntos) :: poligono(int ancho, int alto, int puntos){ 

    this-> x1 = x1i; 

    this-> x2 = x2i; 

    this-> x3 = x3i; 

    this-> y1 = y1i; 

    this-> y2 = y2i; 

    this-> y3 = y3i; 

} 


triangulo :: triangulo(int x1, int x2, int x3, int y1, int y2, int y3, string clasei, const otro&) :: poligono (otro.ancho, otro.alto, otro.puntos){ 

    this-> x1 = otro.x1; 
    this-> x2 = otro.x2; 
    this-> x3 = otro.x3; 
    this-> y1 = otro.y1; 
    this-> y2 = otro.y2; 
    this-> y3 = otro.y3; 

    this->clase = clasei; 




} 

#ifndef TRIANGULO_H 
#define TRIANGULO_H 
#include "poligono.h" 
#include <iostream> 
#include <string> 
using namespace std; 
class triangulo : public poligono{ 

    private: 

     string clase; 

     const int lados = 3; 

     int x1; 
     int y1; 
     int x2; 
     int y2; 
     int x3; 
     int y3; 


    public: 


     triangulo (int x1i, int x2i, int x3i, int y1i, int y2i, int y3i, string clase); 

     triangulo (const &otro); 

     setx1(int x1i); 
     setx2(int x2i); 
     setx3(int x3i); 

     sety1(int y1i); 
     sety2(int y2i); 
     sety3(int y3i); 

     getx1(); 
     getx2(); 
     getx3(); 
     gety1(); 
     gety2(); 
     gety3(); 

     getlados(); 
     getclase(); 

}; 

#endif 
+0

這裏有多個問題。 – 0x499602D2

+5

錯誤信息中的「xxx」是什麼? –

回答

5

對於你提到的問題的方式,你需要#include "triangulo.h",否則編譯器不知道這是什麼triangulo類你指的是。另外,#include <string.h>應該是#include <string>

順便說一句,把using namespace std放在最好的時候並不是很好,但把它放在頭文件中真的很糟糕。另外,如果您發現自己定義了名爲x1,x2,,y1,y2y3的成員變量,那麼您很可能會遇到設計問題。至少,聽起來像一個Pointclassstruct的主要候選人,與某種容器相結合。更有可能的是,如果你首先有一個poligono基類,你通常會期望所有這些功能都包含在其中。