Are class properties in C++?

Started by
15 comments, last by DraconicArchmage 22 years, 4 months ago
I''m currently working on a demo for a game in Visual Basic. Yayaya, I know, but it''s mostly for those who don''t know C/C++ too wekk yet (such as myself). However, I plan on "translating" it into C++ once I get a working algo and design. I was wondering if C++ had anything like the Property Let, Property Get, and Property Set methods in Visual Basic. i.e. Public Property Let TheProperty(WhatToSetTo as Whatever) ClassPropery = WhatToSetTo End Property Or if C++ does it using functions anyways. i.e. Public: int SetWhatever(ToWhatever) { Whatever = ToWhatever; Return Something; } I''m currently using functions to set the private data of my objects, but if C++ has properties, I will change these functions to them. What would you recommend? Hope I made my question clear enough. I appreciate any advice, and thank you for your time.
Advertisement
You are correct in your assessment of the situation, in so much as it is usual to provide public getters and setters and make the underlying variable private ...

If you are using Micro$oft VC++ then you could either provide a COM wrapper to your generic C++, or write the DLL''s as COM. Either way COM provides you with Get and Set properties.

When you port your code to C++ be liberal with your use of const, it is a much underused thing ...

  class Simple{public:   Simple();   ~Simple();   const long get_Value() const;   void set_Value(const long value);private:   long m_Value;}  
MSVC6 supports properties. More about it here:


[edit: enabled hyperlink]

Edited by - Magmai Kai Holmlor on December 21, 2001 1:44:34 AM
Borland C++ Builder supports them too.

Fantastic doctrines (like Christianity or Islam or Marxism or Microsoft-bashing) require unanimity of belief. One dissenter casts doubt on the creed of millions. Thus the fear and hate; thus the torture chamber, the iron stake, the gallows, the labor camp, the psychiatric ward - Edward Abbey
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
If you ever get my reply, I''d like to say thanks. Other than that, I have two even simpler questions: why won''t tabs or 5 spaces work on the forums to indent? Heh. I can''t stand it when I can''t indent paragraphs anymore. I must write too much. And the other: how do you get that lil code box to show up, or is it done using HTML or such? Thanks again.
quote:Original post by DraconicArchmage
why won''t tabs or 5 spaces work on the forums to indent?...how do you get that lil code box to show up, or is it done using HTML or such?

i am guessing that spaces and tabs are ignored because the message board program turns the posts into HTML (which ignores whitespace after the first character of it)...
to put the white box put your stuff between [!source] and [!/source] (but without the !, i just put them to keep the thing from parsing them)... using [!code] and [!/code] will format your stuff without the white box (kinda like the tag in HTML).
you can also use [!i],[!/i],[!b],[!/b] for bold and italic.
for a hyperlink just use a HTML tag...


--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
If you don''t want to bind it to one particular platform just overload operator= and a conversion operator and you have the same functionality
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
quote:Original post by DigitalDelusion
If you don''t want to bind it to one particular platform just overload operator= and a conversion operator and you have the same functionality

Uhh...no.



Fantastic doctrines (like Christianity or Islam or Marxism or Microsoft-bashing) require unanimity of belief. One dissenter casts doubt on the creed of millions. Thus the fear and hate; thus the torture chamber, the iron stake, the gallows, the labor camp, the psychiatric ward - Edward Abbey
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
quote:Original post by Arild Fines
Original post by DigitalDelusion
If you don''t want to bind it to one particular platform just overload operator= and a conversion operator and you have the same functionality

Uhh…no.



uhh…yes…

if you have those then it''s exactly like having set and get functions.


HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
quote:Original post by DigitalDelusion
Original post by Arild Fines
Original post by DigitalDelusion
If you don''t want to bind it to one particular platform just overload operator= and a conversion operator and you have the same functionality

Uhh…no.



uhh…yes…

if you have those then it''s exactly like having set and get functions.




No. With overloading =, you are doing it for the entire class. You use gettor and settor methods to get/set individual properties of the class.


Make it work.
Make it right.
Make it fast.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]

This topic is closed to new replies.

Advertisement