|
-
Jul 1st, 2001, 06:02 PM
#1
Thread Starter
Hyperactive Member
Properties
is there, in C++, such a thing as Property Get and Property Let?
Thanks
Amon Ra
Amon Ra
The Power of Learning.
-
Jul 1st, 2001, 06:06 PM
#2
Monday Morning Lunatic
In Standard C++, not as such. Microsoft C++ has extensions to allow this using __declspec. Normally you'd just use Get and Set functions:
Code:
class TestClass {
public:
inline int GetValue() { return m_iValue; }
inline void SetValue(int iValue) { m_iValue = iValue; }
private:
int m_iValue;
};
Those inlines are there because if it's a one-liner the compiler can save the cost of a function call
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jul 1st, 2001, 06:10 PM
#3
Yup.
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;
}
...will allow...
Code:
myClass SomeVar;
SomeVar.Value = 10;
SomeVar.Set(10); //Does the same thing as above
Z.
-
Jul 1st, 2001, 06:12 PM
#4
Monday Morning Lunatic
Why capitals on the type names?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jul 1st, 2001, 06:49 PM
#5
Thread Starter
Hyperactive Member
Amon Ra
The Power of Learning.
-
Jul 1st, 2001, 07:58 PM
#6
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|