473,326 Members | 2,438 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,326 software developers and data experts.

Private Inner Classes

I'm trying to implement a linked list in C++ but I'm having a problem with an inner class.
Expand|Select|Wrap|Line Numbers
  1. template<class E>
  2. class LinkedList: public List {
  3.     private:
  4.         Node<E> head;
  5.         class Node<E> {
  6.             private:
  7.                 E data;
  8.                 Node* next;
  9.                 Node* prev;
  10.             friend class List;         
  11.         };
  12.     public:
  13.         //constructors and stuff here
  14. };
  15.  
I'm pretty sure I'm messing up generics somehow, and the head variable is giving me a problem
Expand|Select|Wrap|Line Numbers
  1. linkedlist.h:21: error: declaration of ‘class E’
  2. linkedlist.h:6: error:  shadows template parm ‘class E’
  3. linkedlist.h:21: error: ‘template<class E> class 'List’ used without template parameters
  4.  
Dec 14 '08 #1
2 2221
JosAH
11,448 Expert 8TB
Inside the template<class E> template the name E counts as a type name so you don't have to do anything like Node<E> on line four; a class 'Node' is enough.

C++ uses a one pass compiler so you have to define the Node class before you can define a 'head' variable of that type.

Are you sure that your want a Node head and not a Node* head in your List class? (this is not a compiler issue).

kind regards,

Jos
Dec 14 '08 #2
Thank you, Jos. You've helped me many times.

Hopefully my last problem before getting this to compile is this:
Expand|Select|Wrap|Line Numbers
  1. LinkedList<E>::Node<E> curNode;
  2.  
which gives "error: expected primary-expression before ‘>’ token".

Since LinkedList is the enclosing class, this way of defining a Node called curNode makes sense to me but it is apparently wrong?

P.S. Node is now a template as is LinkedList which extends a separate template
Dec 14 '08 #3

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

Similar topics

10
by: Paul Morrow | last post by:
I'm hoping that someone can explain why I get the following exception. When I execute the code... ###################################### class Parent(object): class Foo(object): baz = 'hello...
7
by: Wolfgang Jeltsch | last post by:
Hello, I want to write a list class with an iterator class as an inner class. The iterator class must have access to certain private members of the list class in order to do its job. Here is a...
1
by: Mark Paskin | last post by:
Hello, I'm having difficulty getting template matching to work with inner classes. I've tried to look up the way to fix this in my references, but I haven't found the fix yet. When I try to...
8
by: Etienne Boucher | last post by:
Nested classes are usualy objects made to only live in their parent object instance. In other words... public class Outter { public class Inner { } }
0
by: Chris Fink | last post by:
I have walked through all of the WSE 3 Hands on Labs and got everything working fine. When I create my own certificate and install it in the stores, my client application that is consuming my WSE...
6
by: Philip Potter | last post by:
I have a graph data structure. It goes something like this: class GraphNode { private: friend class Graph; // successor GraphNodes stored as indices of the Graph's array int value; int next1,...
6
by: earthwormgaz | last post by:
Is the following legal? class Outer { class Inner { private: Inner() { } };
2
by: tron.thomas | last post by:
The following code will print a message only once: class PrintOnce: printOnce = True def __init__(self): if PrintOnce.printOnce: print 'Printing once.' PrintOnce.printOnce = False first =...
2
by: andrew_nuss | last post by:
Hi, I have an Array<Ttemplate that specializes on T's in my program that inherit from a base class that I've defined called CtorDtorLess. In my array template, I check if...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.