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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

im new. class variable question

Status
Not open for further replies.
It deppends on function type what you implement:
class xxx
{
int x;
public:
void a() const;
//this function can't change class members,
//except mutable variables
}; John Fill
 
exactly.

make it private and then make its accessor functions const
such as:
Code:
class MyClass{
public:
//...loads of hardcore code
int getVariable()const{return variable;}

private:
int variable; //your data variable
};

so now there's no way to change it unless of course you create a member function that can modify it such as

Code:
void MyClass::setVariable(int newValue){
   variable = newValue;
}
Avendeval Sedai
yavoor@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top