J
Jon Slaughter
I was wondering if there is any big difference(speed/size) when one uses ->
vs . as returning a pointer vs a reference.
i..e in my code I overload [] a lot(cause I have many classes) and I can do
either
object& operator[](int index)
{
if ((index >= NumProperties()) || (index < 0) || (Properties.empty()))
{
throw "Object: Invalid Index!";
}
return *(Properties[index]);
};
or
object* operator[](int index)
{
if ((index >= NumProperties()) || (index < 0) || (Properties.empty()))
{
throw "Object: Invalid Index!";
}
return (Properties[index]);
};
Properties is a vector of pointers. The difference between the two methods
basicaly comes down to using -> and . but I prefer to use . because its
easier to type and consistent with my thinking about fields(while the -> is
basicaly the same its just easier to think about .(not much but...)).
I'm just wondering if there is any reason not to use the first code example
over the second one(as far as optimization is concerned).
Thanks,
Jon
vs . as returning a pointer vs a reference.
i..e in my code I overload [] a lot(cause I have many classes) and I can do
either
object& operator[](int index)
{
if ((index >= NumProperties()) || (index < 0) || (Properties.empty()))
{
throw "Object: Invalid Index!";
}
return *(Properties[index]);
};
or
object* operator[](int index)
{
if ((index >= NumProperties()) || (index < 0) || (Properties.empty()))
{
throw "Object: Invalid Index!";
}
return (Properties[index]);
};
Properties is a vector of pointers. The difference between the two methods
basicaly comes down to using -> and . but I prefer to use . because its
easier to type and consistent with my thinking about fields(while the -> is
basicaly the same its just easier to think about .(not much but...)).
I'm just wondering if there is any reason not to use the first code example
over the second one(as far as optimization is concerned).
Thanks,
Jon