1

コンパイルしようとすると、コードの最初の行で「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
4

1 に答える 1

7

For the issue you mention, you need to #include "triangulo.h", otherwise the compiler has no idea what this triangulo class you are referring to is. Also, #include <string.h> should be #include <string>.

In passing, putting using namespace std is not great at the best of times, but putting it in a header file is really bad. Also, if you find yourself defining member variables called x1, x2, x3, y1, y2, and y3, there's a pretty good chance you have a design issue. At a minimum, sounds like a prime candidate for a Point class or struct, in combination with some kind of container. More likely, if you have a poligono base class in the first place, you'd normally kind of expect all that point functionality to be contained within that.

于 2013-10-21T00:39:37.820 に答える