Code: Select all
class aBase
{
public:
int getInt(){ return mInt; };
int setInt( int int ){ mInt = int; };
protected:
int mInt;
}
Code: Select all
class aBase
{
public:
int mInt;
}
Code: Select all
class aBase
{
public:
int getInt(){ return mInt; };
int setInt( int int ){ mInt = int; };
protected:
int mInt;
}
Code: Select all
class aBase
{
public:
int mInt;
}
Compiler most likely inline those functions. You won't see any speed difference.LJS wrote:would it make the rendering loop faster leaving microsecs for fun stuff?
Code: Select all
class aBase
{
public:
inline int getInt(){ return mInt; };
inline int setInt( int int ){ mInt = int; };
protected:
int mInt;
}
Code: Select all
aBase test;
int a = test.getInt();
int b = 25;
test.setInt(b);
Code: Select all
aBase test;
int a = test.mInt;
int b = 25;
test.mInt = b;
Code: Select all
class cBase
{
public:
Ogre::Vector3 Position;
}
...
func:
{
base->Position.z = 1;
}
Code: Select all
class cBase
{
protected:
Ogre::Vector3 mPosition;
public:
Ogre::Vector3 getPosition(){ return mDirection; };
void setPosition( Ogre::Vector3 direction ){ mDirection = direction; };
}
...
func:
{
Ogre::Vector3 dir = base->getPosition();
pos.z = 1;
base->setPosition( pos );
}
As far as I know, no extra flexability is added, they're declared but never even used in any other way.bstone wrote:The code would be the same in both cases. Why lose the extra flexibility then?
Still I will need to call it twice without any data change has been made. Manipulating the data in the middle makes it worth calling those :pBrocan wrote:...compiler will put the calls as direct access to variables
Code: Select all
class cBase
{
protected:
Ogre::Vector3 mDirection;
public:
Ogre::Vector3& getPosition(){ return mDirection; };
void setPosition( Ogre::Vector3 direction ){ mDirection = direction };
}
No it won't work.LJS wrote: Or would base->getPosition().x = 1; work too?
Code: Select all
Ogre::Vector3 getPosition(){ return mDirection; };
Code: Select all
Ogre::Vector3 &getPosition(){ return mDirection; }; // Note the & sign
Code: Select all
base->getPosition().x = 1;
The flexibility is in the ability to shuffle the member variable around (e.g. changing its internal presentation, making it calculated based on some other value, moving it to another class and redirecting the access, etc.). All that without ever changing dependent code. Once you have a moderately complex/large project that has to evolve - you'll learn to appreciate that quick enoughBrocan wrote:As far as I know, no extra flexability is added, they're declared but never even used in any other way.