wierd template problem

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2008
Posts: 119
Reputation: kux is on a distinguished road 
Solved Threads: 10
kux kux is offline Offline
Junior Poster

wierd template problem

 
0
  #1
Jun 26th, 2009
take a look at this code:
  1.  
  2. template <class T>
  3. class C {
  4. public:
  5.  
  6. class A {
  7.  
  8. protected:
  9. int x;
  10. };
  11.  
  12. class B: public A {
  13. protected:
  14. void write() {
  15. cout << x << endl;
  16. }
  17. };
  18.  
  19. };

when I try to compile with g++ i get:
test.cpp: In member function ‘void C<T>::B::write()’:
test.cpp:18: error: ‘x’ was not declared in this scope

If I remove the template argument of class C all workes fine ( of course )
Does anyone have an ideea of what is going on?

thx in advance
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 476
Reputation: csurfer is just really nice csurfer is just really nice csurfer is just really nice csurfer is just really nice csurfer is just really nice 
Solved Threads: 76
csurfer's Avatar
csurfer csurfer is offline Offline
Posting Pro in Training

Re: wierd template problem

 
0
  #2
Jun 26th, 2009
Well where are you exactly using template functionalities in this code segment ??? I don't see its usage anywhere in the code given by you.
I Surf in "C"....
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,721
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 501
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: wierd template problem

 
0
  #3
Jun 26th, 2009
Use this

  1. void write() {
  2. cout << this->x << endl;
  3. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 119
Reputation: kux is on a distinguished road 
Solved Threads: 10
kux kux is offline Offline
Junior Poster

Re: wierd template problem

 
0
  #4
Jun 26th, 2009
Originally Posted by csurfer View Post
Well where are you exactly using template functionalities in this code segment ??? I don't see its usage anywhere in the code given by you.
It's just a sample I made to hilight the compile error. I might use the template parameter on other methods I didn't post.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 279 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC