|
-
November 3rd, 2009, 02:05 PM
#14
Re: overwrite virtual template methods
I agree that qualifying the full name is the solution.
But I'm morw with kempofighter on this.
 Originally Posted by itcmelo
Code:
int main()
{
B b;
int i = 10;
bool x = b.IsValid(i); //Error, only IsValid(int, int) from B is visible.
/* ... */
}
call to the b.IsValid was an error even before it made
because it was called on the object, not through a reference type.
so in this case,
my understanding is that it was the vTable lookup mechanism that called b.IsValid(i) invalid,
not the name hiding.
I believe Paul was right on this when he showed the comeau version of the error
Code:
#include <iostream>
template <typename T>
struct Base
{
Base() : x(T()) {}
virtual ~Base(){}
virtual void call(const T y) const
{
std::cout << x + y;
}
virtual void call() const
{
std::cout << x;
}
protected:
T x;
};
struct Derived : public Base<int>
{
virtual void call(const int y) const
{
std::cout << x + y;
}
};
int main()
{
Derived d;
Base<int>& ref = d;
ref.call(); // valid with a warning
}
Here, we're not using the using declaration.
I looked up Scott Meyer's effective C++,
and under "Never redefine an inherited non-virtual function",
he's also using reference types to illustrate the behavior
If name hiding does occur before name look up happens in virtual overload resolution,
(which I believe should happen afterwards)
then like kempofighter, I'm lost as to why.
Last edited by potatoCode; November 3rd, 2009 at 02:13 PM.
Reason: fixed some typo
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|