I have a base class that looks like the following.
template<typename T>
class Base
{
public:
Base(int someValue);
virtual T someFunc() =0;
};
template<typename T>
Base<T>::Base(int someValue)
{}
And then the following.
#include "base.hpp"
class Foo
: public Base<Foo>
{
public:
Foo(int someValue);
virtual Foo someFunc();
};
Foo::Foo(int someValue)
: Base(someValue)
{}
I get the following error from gcc 4.2.1.
error: class ‘Foo’ does not have any field named ‘Base’
I should mention this compiles fine on my Fedora box wich is running gcc 4.6.2. This error occurs when compiling on my os x Lion machine.
Thanks in advance for the help.
EDIT
Problem seems that I am not indicating type of template in the Foo class when calling the constructor. The following fixes the error in os x.
: Base<Foo>(someValue, parent)
EDIT
Yes this does look like a bug. What I mentioned before fixes the error under os x and code compiles fine in fedora with that fix. Will go and see if there is an update to gcc in os x.
First:
And
Base
should be a valid injected-class-name for the base here (that is, you can use it in place ofBase<T>
):I haven't found anything to indicate that this doesn't apply in the ctor-initializer, so I'd say that this is a compiler bug.
My stripped-down testcase fails in GCC 4.1.2 and GCC 4.3.4 but succeeds in GCC 4.5.1 (C++11 mode). It seems to be resolved by GCC bug 189; in the GCC 4.5 release notes:
My stripped-down testcase with Qt abstracted out: