Sathyaish
March 16th, 2005, 08:47 AM
#include<iostream.h>
class Num
{
public:
Num(int num)
{
_num = num;
}
int GetNum()
{
return _num;
}
void DoSomething()
{
_num += GetNum(); /*Is this more expensive or the same as _num += _num? *
When calling GetNum, the function does not have to prepare
its own local stack but has to pop the value from the stack
local to the class, which is the same cost as accessing the
private variable _num directly. However, the caller has to
record its state before the call and also its return address.
Thoughts please.*/
}
private:
int _num;
};
class Num
{
public:
Num(int num)
{
_num = num;
}
int GetNum()
{
return _num;
}
void DoSomething()
{
_num += GetNum(); /*Is this more expensive or the same as _num += _num? *
When calling GetNum, the function does not have to prepare
its own local stack but has to pop the value from the stack
local to the class, which is the same cost as accessing the
private variable _num directly. However, the caller has to
record its state before the call and also its return address.
Thoughts please.*/
}
private:
int _num;
};