I am trying to compile a code like this:
#include <iostream>
using namespace std;
class CPosition
{
private:
int itsX,itsY;
public:
void Show();
void Set(int,int);
};
void CPosition::Set(int a, int b)
{
itsX=a;
itsY=b;
}
void CPosition::Show()
{
cout << "x:" << itsX << " y:" << itsY << endl;
}
class CCube
{
friend class CPosition;
private:
CPosition Position;
};
main()
{
CCube cube1;
cube1.Position.Show();
cube1.Position.Set(2,3);
cube1.Position.Show();
}
but get 'CCube :: Position' is not available in the main () function 3 times. I want the CPosition class to be declared outside of CCube so that I can use it in future in new classes, for example. CBall :) but how can I make it work without using inheritance. Is it possible:)?
Regards, PC
source
share