one more way, that is not always acceptable (and, probably, because of it evilrix didn't mention it) is here:
#include <IOSTREAM>
using namespace std;
class CPoint:
{
int m_nX;
int m_nY;
public:
CPoint(int x, int y) : m_nX(x), m_nY(y) {}
int& X() { return m_nX; }
int& Y() { return m_nY; }
};
int main()
{
CPoint point(10, 10);
point.X() = 20;
point.Y() = 40;
cout << " X = " << point.X() << endl;
}
Main Topics
Browse All Topics





by: evilrixPosted on 2009-11-03 at 06:27:13ID: 25729216
Normal (unmanaged) C++ has no concept of properties. You simulate them by implementing get and set functions.
class myclass
{
public:
void set_someval(int n);
int get someval() const;
};