R
Richard Hayden
Hi,
I have a question regarding the type of the 'this' reference for virtual
functions.
Say for example, you have:
class C1 {
....
public:
virtual void func() { ... }
....
};
class C2 : public C1 {
....
// Assume C2 does not override func
....
};
Say you then create a C2 and call the 'func()' function on it via a
reference to C1, does the 'this' reference in func() have type
'reference to C1' or 'reference to C2'? Clearly, if I had overridden
func in C2, it would obviously be 'reference to C2', but does this also
hold even if func is not overridden in C2? This is probably pretty much
a non-question since it doesn't at first appear as if there would
actually be a situation where it would matter, however, I was thinking
from the POV of overload resolution, when the implied object parameter
is considered.
Thanks,
Richard Hayden.
I have a question regarding the type of the 'this' reference for virtual
functions.
Say for example, you have:
class C1 {
....
public:
virtual void func() { ... }
....
};
class C2 : public C1 {
....
// Assume C2 does not override func
....
};
Say you then create a C2 and call the 'func()' function on it via a
reference to C1, does the 'this' reference in func() have type
'reference to C1' or 'reference to C2'? Clearly, if I had overridden
func in C2, it would obviously be 'reference to C2', but does this also
hold even if func is not overridden in C2? This is probably pretty much
a non-question since it doesn't at first appear as if there would
actually be a situation where it would matter, however, I was thinking
from the POV of overload resolution, when the implied object parameter
is considered.
Thanks,
Richard Hayden.