Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > Standard C, C++
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 12-21-2007, 02:49 AM   #1 (permalink)
messenjah
Recruit
 
Join Date: Dec 2007
Posts: 2
messenjah is on a distinguished road
Iterator definition outside class

I am trying to implement a graph class which allows neighbour access via an iterator. I have the following so far.
Code:
template <typename T> class Graph { public: class iterator; friend class iterator; // Lots of constructors, destructor and other functions iterator begin(){ iterator it; it.index = 0; it.container = this; return it; } iterator end(); // Other functions, protected and private data }; template <typename T> class Graph<T>::iterator { friend class Graph<T>; public: // Lots of constructors, destructor and other functions protected: int index; Graph<T>* container; }; // Some other code template <typename T> Graph<T>::iterator Graph<T>::end(){ // Error Line iterator it; it.index = this->maxsize; it.container = this; return it; }
The point I want to make here is that the iterator function begin is implemented in the actual Graph class declaration while the other one end is outside the class. When I try to precompile the header I get an error expected constructor, destructor, or type conversion before "Graph" at the indicated line (Error Line). When I define both iterator functions inside the class evrything compiles OK. Ideally I would like both iterator functins outside the class. Any ideas anyone. btw I am using g++ 3.4.4-2 on RH9 Enterprise.
__________________
messenjah is offline   Reply With Quote
Old 01-03-2008, 12:03 AM   #2 (permalink)
priji
Recruit
 
Join Date: Jan 2008
Posts: 5
priji is on a distinguished road
Thank you very much
__________________
priji is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help me pass my class Negative6 Java 1 05-03-2007 04:28 PM
[C#] Casting from derived class to base class Melon00 MS Technologies ( ASP, VB, C#, .NET ) 0 06-06-2006 08:34 AM
Class using a specific instance of another class? is this possible? abs Standard C, C++ 5 02-08-2005 03:12 PM
to put data methods inside class or not? sde Java 2 05-25-2004 04:09 PM
Java Class Basics: Static Methods bdl Java 0 02-29-2004 02:25 PM


All times are GMT -8. The time now is 09:28 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle