943,714 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 396
  • C++ RSS
Jun 26th, 2009
0

wierd template problem

Expand Post »
take a look at this code:
C++ Syntax (Toggle Plain Text)
  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
Similar Threads
kux
Reputation Points: 66
Solved Threads: 11
Junior Poster
kux is offline Offline
119 posts
since Jan 2008
Jun 26th, 2009
0

Re: wierd template problem

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.
Reputation Points: 485
Solved Threads: 88
Posting Pro
csurfer is offline Offline
564 posts
since Jan 2009
Jun 26th, 2009
0

Re: wierd template problem

Use this

C++ Syntax (Toggle Plain Text)
  1. void write() {
  2. cout << this->x << endl;
  3. }
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jun 26th, 2009
0

Re: wierd template problem

Click to Expand / Collapse  Quote originally posted by csurfer ...
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.
kux
Reputation Points: 66
Solved Threads: 11
Junior Poster
kux is offline Offline
119 posts
since Jan 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: enum with % (remainder) operator
Next Thread in C++ Forum Timeline: plz solve this





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC