Results 1 to 6 of 6

Thread: Properties

  1. #1

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Question Properties

    is there, in C++, such a thing as Property Get and Property Let?
    Thanks
    Amon Ra
    Amon Ra
    The Power of Learning.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  3. #3
    Zaei
    Guest
    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.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  5. #5

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Cool

    Thanks guys!
    Amon Ra
    Amon Ra
    The Power of Learning.

  6. #6
    Zaei
    Guest
    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
  •  



Click Here to Expand Forum to Full Width