Is an nonstatic member function call the same as an ordinary function call
(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 same
as an ordinary function call.
--Not exactly the same, but fundamentally the same.
Ah ok sorry misunderstanding.
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 §5.2.2).
Ok so this is the syntaxical rules we must obey, is it not?
-- 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.
Now I find what you say here slightly confusing.
You say "beyond that" which I take to mean ..Beyond the definition of the
standard, in your previous sentence.
Then you go on about what the standard requires for initialisation of the
this pointer.
Surely we must either speak in terms of the standard or not, you seem to
jump in and out of standards context when it suits you.
But ignoring that, what you actually speak about is initialisation of the
this pointer, which I presume is a pointer, yes?
You seem to intepret the this pointer a reference, surely the this pointer
is not required to be converted to a refernece, this seems like an
unneccessarry converion forced upon a compiler i.e :
pointer -> reference -> pointer. (why?)
Don't get me wrong I understand what you are saying about the underlying
mechanics of a nonvirtual function call, but the issue here is:
Are we allowed to do this as per the C++ std, which is the general concensus
of this group to determine proper C++ code.
--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.
I see again you introduce references , this obviously has seem to be a
requirement for you argument.
I don't see the need to have any references when calling a member function,
therefore this continued use of referneces in your demonstrations leads me
to believe there is something wrong.
Can you not give an example using simple pointers ?
-- But in the
--other thread, you were looking for things that would make
--member functions fundamentally different from non-members.
I'm not looking for something to make them different , I know they are
different. I'm trying to understand why you think it's beneficial to think
of them as the the same.
One word proves they're different ...virtual.
But I realise you are talking about non virtual and I don't try to be
awkward by suggesting this , I am simply pointing out the onus is not on me
to prove a difference.
As below we must respectively assume you are obviously not talking about
virtual functions
--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.
Yes I agree.
But that syntax difference means we are not allowed to do the following, or
does it:
struct ObjT{
void mthd(){};
};
ObjT o;
mthd(o); /*I do not understand this is uncharted waters to me*/
mthd(&o) /*or is this what you propose?its not a reference I know*/
o.mthd() /*my normal calling syntax*/
I don't know if any of the above is proper code I didn't try to compile
anything, please can you explain what is valid as per the standard.