This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Deriving from templated classes


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

Attachment: signature.asc
Description: This is a digitally signed message part.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]