Hello people of the forum.
i'm having a problem, i make a class inside another class, and now i can't create(PS: i make in a .h/.cpp)the objects for use the functions of classes.
Source?!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
HEADER:
#ifndef FUNCTIONS_H_INCLUDED
#define FUNCTIONS_H_INCLUDED
class Graphic {
public :
class Draw {
public :
void Pixel(COORD Pos, COLORREF color);
void Line(COORD Init, COORD End, COLORREF Color);
void Rectangle(COORD Pos, COORD Radius, COLORREF Color, float angle);
void Circle(COORD Pos, int radius, COLORREF Color, float angle);
};
};
#endif // FUNCTIONS_H_INCLUDED
Create\expose an object of type Draw in Graphic say
class Graphic
{
//existing code
//
//
//new code
private:
Draw m_Draw;
public:
Draw GetDraw(){return m_Draw;}
}
Now create an object of type Graphic as
Graphic MyGraphicObj;
Now you can use like
MyGraphicObj.GetDraw().Line();
Note:-Exposing a class or member variable as public breaks encapsulation.
You should think\code always by remembering the laws of OOPS.