Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / April 2006



Tip: Looking for answers? Try searching our database.

Template inheritance is not working in Xcode

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
steve@walkereffects.com - 19 Apr 2006 18:31 GMT
Hi,

I'm porting more code over to Xcode from Codewarrior and have run into
a new problem with template classes. I have a template class that is
derived from a template class derived from another non-template
class... so it is 3 levels deep. The first derived template class works
fine and I can access members defined in the base class. However, the
higher level template class produces an error when trying to access
members of the base class. This should work.

Am I missing something here? The following code will not compile:

class TestBase {
 public:
    long    mTest;
};

template<typename X>
class TestA : public TestBase {
 public:
    long    TestMeA() { return mTest + 1; } // this is fine
};

template<typename X>
class TestB : public TestA<X> {
 public:
    long    TestMeB() { return mTest + 1; } // compile error: 'mTest' was not
declared in this scope
};

Thanks for any help!

Steven J. Walker
Walker Effects
www.walkereffects.com
steve@walkereffects.com
steve@walkereffects.com - 25 Apr 2006 04:31 GMT
I found the solution to this problem... the member needs to qualified
by the first template class:

     long    TestMeB() { return TestA<X>::mTest + 1; }
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.