Wednesday, August 12, 2009

More on operator overloading

So this whole problem led me to think about some other issues.


class Box
{
bool
contains
( double const & location
) const;
};


so someone would call:


Box box(....);
if (box.contains(location))
{


In c++ the "contains" could be extracted from the class, but that would result in this call:


Box box(...);
if (contains(box, location))
{


This is starting to become less clear

And now we break from c++


if (box contains(location)) // or ( box contains location )
{


Examining the first class method example, a c++ compiler would roughtly translate this into something like

Box::contains(pointer to instance box, location);

while the second would resolve to calling

contains(box, location);

No comments:

Post a Comment