473,395 Members | 1,454 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.

Templates and Iterators

card
10
Hi everyone,

Can anybody explain why this won't build and what the error is? The error is with the list iterator in the TestClass class. Basically, I have a two templated classes, Item and TestClass. TestClass uses Item to define on of its template parameters.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <list>
  5. #include "test.h"
  6.  
  7. using std::vector;
  8. using std::string;
  9. using std::list;
  10.  
  11. template<class Key, class Element>
  12. class Item
  13. {
  14. private:
  15.     Key _key;
  16.     Element _element;
  17. };
  18.  
  19. template<class Key, class Element, class Entry=Item<Key,Element> >
  20. class TestClass
  21. {
  22. private:
  23.     list<Entry>::iterator  myIter;
  24. };
  25.  
  26. int main(int argc, char *argv[])
  27. {
  28.     vector< list<TestClass<string, int> > > _v;
  29.     list<TestClass<string, int> >::iterator _it;
  30.  
  31.     return 0;
  32. }
  33.  
  34.  
The build error using g++ 4.2.3 is:

test.C:33: error: type ‘std::list<Entry, std::allocator<_Tp> >’ is not derived from type ‘TestClass<Key, Element, Entry>’
test.C:33: error: expected ‘;’ before ‘myIter’

I can't figure this one out. Many thanks.

-David
Oct 22 '08 #1
2 1271
newb16
687 512MB
I have no idea if it is working, but at least it compiles ( when i removed include "test.h" line )
Expand|Select|Wrap|Line Numbers
  1. typename list<Entry>::iterator  myIter; 
  2.  
Oct 22 '08 #2
card
10
Yeah, sorry about leaving the "test.h" include in there. Thanks for the reply. Works great.
Oct 23 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tom McCallum | last post by:
I have looked all afternoon and I can't find a definite answer on the following problem. I have defined a class My question is why can't I define my iterator below? template<class T> class...
7
by: Jürgen Kaminski | last post by:
Hello all, I got some legacy code where a template implements a non-templated interface. These classes are really HUGE, but it boils down to the following structure: class BaseClass { public:...
5
by: jimmy | last post by:
I am trying to simulate typedef template similar to the suggestion of Herb Sutter in the following article: http://www.gotw.ca/gotw/079.htm However when implementing typedef templates according...
5
by: Zeppe | last post by:
Hi all! my problem is this one, I think that it could be a common one, maybe a pattern, so if you can help me somehow it would be great. Let's suppose I have a class Base class Base { //...
104
by: JohnQ | last post by:
Well apparently not since one can step thru template code with a debugger. But if I was willing to make the concession on debugging, templates would be strictly a precompiler thing? I have a...
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.