Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get/Set Properties - Beginner VC++ 5

Status
Not open for further replies.

huntjr

Programmer
Jun 12, 2000
23
US
I am extremely new to VC++ 5. I have much experience in VB5, and I have a question regarding the two.<br><br>In Visual C++ 5, how do you access the nondefault poperties of an object? I know that you can set a control variable for default fields and use UpdateData.<br><br>I would appreciate any help, as I am very new to C++.
 
Dear Huntjr,<br><br>C++ object have three scopes of attributes.<br>1) public<br>2) protected<br>3) private<br><br>The scope applies to every attribute, member variables and functions (methods) alike.<br><br>According to the most widely prescribed tenants of OOP no member variables should be given 'public' scope. Any object that is developed to this stringent standard would only provide access to data members through public member functions.<br><br>class foo{<br>protected:<br>&nbsp;&nbsp;CString _name;<br>public:<br>&nbsp;&nbsp;foo(){} // constructor<br>&nbsp;&nbsp;virtual ~foo(){} // destructor<br><br>public:<br>&nbsp;&nbsp;// public accessor functions<br>&nbsp;&nbsp;void setname( CString name){ _name = name; }<br>&nbsp;&nbsp;void setTheName( CString name) { _name = name; }<br>&nbsp;&nbsp;void makesNoSense( CString name) { _name = name; }<br><br>&nbsp;&nbsp;const CString& getname(){ return _name; }<br>&nbsp;&nbsp;const CString& whatever() { return _name; }<br>}<br><br>As you can see by my example there is no 'standard' function for setting / getting data member variable values in C++. The developer can name functions(methods) and member variables anything he/she likes.<br><br>You really need to get some beginner C++ material to work with. The standard Visual C++ documentation will not help much in learning C++ techniques and Object Oriented Programming.<br><br>Hope this helps<br>-pete<br>
 
Thanks a bunch for your help, pete. I'm using a Teach Yourself in 21 Days books. I've learned pretty good with books; hopefully it will be same with VC++.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top