is there, in C++, such a thing as Property Get and Property Let?
Thanks
Amon Ra
Printable View
is there, in C++, such a thing as Property Get and Property Let?
Thanks
Amon Ra
In Standard C++, not as such. Microsoft C++ has extensions to allow this using __declspec. Normally you'd just use Get and Set functions:Those inlines are there because if it's a one-liner the compiler can save the cost of a function call :)Code:class TestClass {
public:
inline int GetValue() { return m_iValue; }
inline void SetValue(int iValue) { m_iValue = iValue; }
private:
int m_iValue;
};
Yup.
...will allow...Code:class myClass
{
public:
INT Get()
{
return myVal;
}
VOID Set(INT newVal)
{
myVal = newVal;
return;
}
__declspec( property ( get = Get, put = Set))INT Value;
private:
INT myVal;
}
Code:myClass SomeVar;
SomeVar.Value = 10;
SomeVar.Set(10); //Does the same thing as above
Z.
Why capitals on the type names?
Thanks guys!
Amon Ra
Dunno, just like the way they look. They fit with lots of other type names (especially Win32API types =). Ive been using them so much in the last couple of months, i cant stop. You can find them all in windows.h
Z.