Deriving from templated classes

Lothar Braun lothar@lobraun.de
Fri Nov 16 15:35:00 GMT 2007


Hi,

i have the following code snipplet and tried to compile it with g++ -c 
main.cpp

template <class T>
class Foo
{
public: 
        T foo;
        int bar;
};
 
template <class A>
class Bar : public Foo<A>
{
public: 
        void foobar()
        {
                bar++;
                foo = 1;
        }
};

I get the error messages (using g++ 4.1.2)

main.cpp: In member function 'void Bar<A>::foobar()':
main.cpp:15: error: 'bar' was not declared in this scope
main.cpp:16: error: 'foo' was not declared in this scope

This seems strange to me, because i think "bar" and "foo" should be within the 
namespace of "class Bar". The code compiles if i substitute "bar++" 
with "Foo<A>::bar++" and "foo = 1" with "Foo<A>::foo = 1".

I tried to compile the code snipplet above using compilers from diffrent 
vendors (intel and m$). Both compiled the code without any errors or 
warnings.

My question is: Does gcc do the right thing (tm) or should that behavior 
reported as a bug? (i tried to search the bug database but wasn't able to 
find anything that looked similar to the above problem).

Best regards,
   Lothar
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20071116/094e03e1/attachment.sig>


More information about the Gcc-help mailing list