Original Post
In OOP, when you initialize private instance variables, does it matter if you call it through self, like self.setRectX(0) or directly aRect.x = 0?
class ARect
{
public:
ARect(void);
// etc, etc...
private:
int x;
// etc.
};
ARect::ARect(void)
{
x = 0;
}
class ARect
{
public:
ARect();
private:
int x;
};
ARect::ARect()
: x(0) // this is the initialization list
{
}
// similar to assignment inside constructor
int a;
a = 0;
...
// this is what initialization list looks like
int a = 0;
...
SomeObj a;
a = some_initial_value;
...
// OR
SomeObj a = some_initial_value;
...
// u can't do this
const int a;
a = 0;
SomeObj & b;
b = someObj2;
...
// but u can...
const int a = 0;
SomeObj & b = someObj2;
...
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more