0

In order to do apply operations on point M(x,y), I've defined a class POINT2D.h:

#ifndef POINT2D_H_INCLUDED

#define POINT2D_H_INCLUDED

class POINT2D {
    POINT2D ();                    //first constructor 
    POINT2D(double x,double y);    // second constructor

private:
    Point M, PointImage;

public:
    void DeclarerM(){
        std::cout << "Entrer les composantes du point M : " << " ";
        std::cin >> M.x >> M.y;
    }

    Point Trnaslation(Point M);         //Functions applied on Point
    Point Rotation(Point M);
    Point SymetrieAxiale (Point M);
    Point Homothetie(Point M);
};

#endif // POINT2D_H_INCLUDED

and a struct Point in the main:

struct Point{             //structure Point
    double x;                 //the coordinates of the Point
    double y;
};

When I run it I get an error in the class, saying "Point does not name a type". What is the problem?

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
  • 1
    Typically a header is included at the beginning of main .cpp. Thus, your POINT2D class has no knowledge of `struct point` even though it makes heavy use of it. See for forward declaration. – 101010 Nov 14 '15 at 22:53

1 Answers1

0

In C++ before you can use an type it must be declared or defined. So since POINT2D does not know about the Point struct you declared in your main.cpp you cannot use it. You can forward declare Point or you move Point into its own header file and then include it in POINT2D.h and main.

You also have an issue with POINT2D as your constructors are both private. You should add public: before them or move them into the public section that is already in your class.

Community
  • 1
  • 1
NathanOliver
  • 171,901
  • 28
  • 288
  • 402