473,395 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Template inheritance comile problem

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
3 1217
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gandu | last post by:
Could some C++ guru please help me? I have a very odd problem with respect templates and inheritance. I have templatized List class, from which I am inheriting to create a Stack class. All works...
13
by: Walt Karas | last post by:
The following gives an error in the declaration of the member function x() of the class template Tpl, compiliing with a recent version of GCC under Solaris: class A { }; class B { }; ...
3
by: Gandu | last post by:
Could some C++ guru please help me. I have a template based general linked list class that I want to inherit publicly to create a queue class. In the case of non-template inheritance, I can use:...
1
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that I don't understand completely. Im I right if I say the...
2
by: Thomas Kowalski | last post by:
Hi, I would like to write a template class Polygon<VertexTypthere vertex typ can be eigther a pointer or a value typ. It has an attribute: std::vector<VertexTypvertices; And a methode:...
9
by: stephen.diverdi | last post by:
Can anyone lend a hand on getting this particular template specialization working? I've been trying to compile with g++ 4.1 and VS 2005. ...
2
by: aitrob | last post by:
Hi, I have a problem concerning templates/inheritance. I have a code that compiles fine with g++ 4.0.1 (Apple version), but gives a lot of errors with Intel C++ 10.1 (Mac OS X). I'm not sure if...
4
by: Pallav singh | last post by:
I am Facing Problem while creating object of Diamond Ring problem solving using Template Kindly let me known where i am committing ERROR Thanks Pallav #include<iostream.h> #include<string.h>
32
by: Stephen Horne | last post by:
I've been using Visual C++ 2003 for some time, and recently started working on making my code compile in GCC and MinGW. I hit on lots of unexpected problems which boil down to the same template...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.