P
Pete Vidler
Hi folks,
I have a small hierarchy with a virtual method which is overridden in
the most derived class. I also have a method that needs to call two
versions of this.. the most derived and the base class:
#include <iostream>
struct A
{
virtual void Foo() { std::cout << "A::MyFunc" << std::endl; }
};
template< class AType >
struct B : public AType
{
void Bar() { Foo(); AType::Foo(); }
};
struct C : public B< A >
{
virtual void Foo() { std::cout << "C::MyFunc" << std::endl; }
};
int main()
{
B< A >* b = new C;
b->Bar();
delete b;
}
This works fine on gcc-3.3.3. I just read in the changes for the new
version of gcc (http://gcc.gnu.org/gcc-3.4/changes.html) that this is no
longer acceptable (and is unacceptable in standard C++).
Specifically -- "In a template definition, unqualified names will no
longer find members of a dependent base". So B::Bar would have to change to:
void Bar() { this->Foo(); this->AType::Foo(); }
My question is, is this legal C++? I'm hoping it will produce the output:
C::MyFunc
A::MyFunc
And it does on my current compiler, but is it standard C++?
Thanks,
-- Pete
I have a small hierarchy with a virtual method which is overridden in
the most derived class. I also have a method that needs to call two
versions of this.. the most derived and the base class:
#include <iostream>
struct A
{
virtual void Foo() { std::cout << "A::MyFunc" << std::endl; }
};
template< class AType >
struct B : public AType
{
void Bar() { Foo(); AType::Foo(); }
};
struct C : public B< A >
{
virtual void Foo() { std::cout << "C::MyFunc" << std::endl; }
};
int main()
{
B< A >* b = new C;
b->Bar();
delete b;
}
This works fine on gcc-3.3.3. I just read in the changes for the new
version of gcc (http://gcc.gnu.org/gcc-3.4/changes.html) that this is no
longer acceptable (and is unacceptable in standard C++).
Specifically -- "In a template definition, unqualified names will no
longer find members of a dependent base". So B::Bar would have to change to:
void Bar() { this->Foo(); this->AType::Foo(); }
My question is, is this legal C++? I'm hoping it will produce the output:
C::MyFunc
A::MyFunc
And it does on my current compiler, but is it standard C++?
Thanks,
-- Pete