By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,421 Members | 1,127 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,421 IT Pros & Developers. It's quick & easy.

Template inheritance comile problem

P: n/a
I have a prbl. cannot seem to compile this simple code: (might this be a
bug?)

gcc version 4.1.2

//Begin code

template <class T>
class FirstClass{
public:
T a;
};

template <class T>
class SecondClass : public FirstClass<T>{
public:
T func(){return a;}
};

int main(){}

//End Code

Compiler

test.cpp: In member function T SecondClass<T>::func():
test.cpp:10: error: a was not declared in this scope
Feb 24 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Helge wrote:
I have a prbl. cannot seem to compile this simple code: (might this be a
bug?)

gcc version 4.1.2

//Begin code

template <class T>
class FirstClass{
public:
T a;
};

template <class T>
class SecondClass : public FirstClass<T>{
public:
T func(){return a;}
try this line:
T func(){return this->a;}
};

int main(){}

//End Code

Compiler

test.cpp: In member function T SecondClass<T>::func():
test.cpp:10: error: a was not declared in this scope
Feb 24 '07 #2

P: n/a
Helge wrote:
I have a prbl. cannot seem to compile this simple code: (might this be a
bug?)

gcc version 4.1.2

//Begin code

template <class T>
class FirstClass{
public:
T a;
};

template <class T>
class SecondClass : public FirstClass<T>{
public:
T func(){return a;}
};

int main(){}

//End Code

Compiler

test.cpp: In member function T SecondClass<T>::func():
test.cpp:10: error: a was not declared in this scope
Gianni told you the answer, but no it isn't a bug. It's 'two phase
lookup', a complicated subject. Try googling if you want more enlightenment.

john
Feb 24 '07 #3

P: n/a
John Harrison wrote:
>>
template <class T>
class SecondClass : public FirstClass<T>{
using FirstClass<T>::a;
>public:
T func(){return a;}
};

Gianni told you the answer, but no it isn't a bug. It's 'two phase
lookup', a complicated subject. Try googling if you want more
enlightenment.
http://www.parashift.com/c++-faq-lit...html#faq-35.19

--
Maksim A. Polyanin
http://grizlyk1.narod.ru/cpp_new

"In thi world of fairy tales rolls are liked olso"
/Gnume/
Feb 25 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.