Templates + Inheritance problem

John Gateley gateley@jriver.com
Thu Jul 19 15:26:00 GMT 2007


Hi, I've found strange behavior, possibly a bug, but more likely a
problem with my understanding. Here's the code:

template<class KEY> class Foo {
public:
	void Baz() {}
};
template<class KEY> class Bar : public Foo<KEY> {
public:
	void Bum() { Baz(); }
};

(I know it doesn't make much sense, I reduced the problem
down to simplest terms). I get an error compiling:

gateley@gateley:~/tmp$ g++ -c Foo.C 
Foo.C: In member function 'void Bar<KEY>::Bum()':
Foo.C:11: error: there are no arguments to 'Baz' that depend on a template parameter, so a declaration of 'Baz' must be available
Foo.C:11: error: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)

Can someone tell me why Baz is undeclared here?

version:
gateley@gateley:~/tmp$ g++ -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)


Thanks,

j

-- 
John Gateley <gateley@jriver.com>



More information about the Gcc mailing list