I had a problem, which I eventually reduced down to this simple example:
template <int dimensions> class Base {
protected:
Base(void) {}
public:
virtual ~Base(void) {}
void base_method(void) {}
};
template <int dimensions> class MyClass : public Base<dimensions> {
public:
MyClass(void) : Base<dimensions>() {
base_method();
}
~MyClass(void) {}
};
This compiles fine on MSVC 2010, but fails with g++ 4.6:
main2.cpp: In constructor âMyClass<dimensions>::MyClass()â:
main2.cpp:12:16: error: there are no arguments to âbase_methodâ that depend on a template parameter, so a declaration of âbase_methodâ must be available [-fpermissive]
main2.cpp:12:16: note: (if you use â-fpermissiveâ, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
What’s going on?
you have to do:
or
Compilers generally will not consider methods in templated base class for function resolution.