![]() |
|
#1
|
|||
|
|||
Return pointer to template's nested class problem(Sorry for the subject..)
I had hoped to reveal my linked list implementation to the world this evening, but alas, I ran into a problem I can't overcome. The problem is, as best described, this. I have a class LinkedList, in which I have a nested class Node. Some of my methods in LinkedList return pointers to class Node objects. Everything seemed to work (as best I could test) before templating the LinkedList class. After templating I get the following warnings and errors on my method definitions that try to return pointer to Node objects Code:
Here are the class declarations CPP / C++ / C Code:
And here are the method definitions CPP / C++ / C Code:
So there's probably something amiss in the scoping of Node class? But I don't know what, since other methods like CPP / C++ / C Code:
Yes, I tried looking for explanations, but didn't come up with any. Or I just missed them as irrelevant. |
|||
|
#2
|
|||
|
|||
Re: Return pointer to template's nested class problemOkay, in the morning I'm back in business and found this poor solution. Making the methods inline works. As in the following
CPP / C++ / C Code:
Now apparently I don't want to use this solution for more complex methods, so I would be grateful on tips how to get this to work non-inline. |
|
#3
|
|||
|
|||
Re: Return pointer to template's nested class problemYet another morning and more business.
So I thought "I wonder how this compiles on GCC" and went off to test it. And, believe it or not, GCC told me in plain English what was wrong. Here's how it's supposed to be for those interested. CPP / C++ / C Code:
However, before getting this plain-Englished answer handed to me, I realized that returning a Node is just plain wrong. It's the data I want to return, not Node. So I changed the design already and this is not that relevant in my linked list anymore, but might come in handy sometime. |
Recent GIDBlog
Not selected for officer school by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Hard drive/CPU Diagnoses Issues | binarybug | Computer Hardware Forum | 1 | 22-Jan-2007 19:23 |
| Pointer Usage in C++: Beginner to Advanced | varunhome | C++ Forum | 0 | 19-Aug-2005 09:25 |
| [Tutorial] Pointers in C (Part II) | Stack Overflow | C Programming Language | 0 | 27-Apr-2005 17:36 |
| C++ file I/O | CronoX | C++ Forum | 36 | 09-Mar-2004 17:28 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The