Re: function calls
On Feb 22, 11:41 am, "Paul" <pchris...@yahoo.co.uk> wrote:
Is an nonstatic member function call the same as an ordinary function cal=
l
(with a hidden parameter)?
Two people , namely James Kanze and Itaj Sherman have been trying to
persuade me that a call to a nonstatic member function is exactly the sam=
e
as an ordinary function call.
Not exactly the same, but fundamentally the same.
I disagree with them because I think the C++ standard disagrees with them=
..
The C++ standard does specify significant differences in the
calling syntax (e.g. in =A75.2.2). Beyond that, however, it
requires the this pointer to be initialized exactly as if it
were a reference to an object (except that it is initialized
with pointer type, and not with reference type). And it
certainly treats them the same in overload resolution. There's
no fundamental difference between them.
There are other subtle differences: a non-const member function
can be called on a temporary, where as a non-const reference
cannot be initialized with a temporary, for example. But in the
other thread, you were looking for things that would make
member functions fundamentally different from non-members.
Where as I fail to see anything but syntax differences between
titi and tata in the following:
struct Toto
{
void titi() const;
friend void tata(Toto const&);
};
This is, of course, an extreme case of similarity. But my point
is that except for syntax, member functions have a series of
characteristics that can, in specific cases, apply to non member
functions as well.
--
James Kanze