错误:xxx 不命名类型

  • 本文关键字:类型 xxx 错误 c++
  • 更新时间 :
  • 英文 :


尝试编译代码时,我在代码的第一行收到错误"xxx 没有命名类型"。知道"poligono"是"triangulo"的基类,我写了.cpp和.h文件。

我想知道如何修复此错误

#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

对于你提到的问题,你需要#include "triangulo.h",否则编译器不知道你所指的这个triangulo类是什么。另外,#include <string.h>应该是#include <string>的。

顺便说一下,在最好的时候放using namespace std不是很好,但把它放在头文件中真的很糟糕。此外,如果你发现自己定义了名为x1x2x3y1y2y3的成员变量,那么你很有可能遇到了设计问题。至少,听起来像是 Point classstruct的主要候选者 ,与某种容器结合使用。更有可能的是,如果您首先有一个poligono基类,您通常会期望所有点功能都包含在其中。

相关内容

最新更新