gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Iterator idiocy....

#43136 - blaisef01 - Thu May 19, 2005 12:23 pm

Can any one tell me why this doesn't compile?

/*--------------------
C INCLUDES
--------------------*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include <math.h>

/*--------------------
CPP INCLUDES
--------------------*/
#include <string>
#include <list>

/*--------------------
NDS INCLUDES
--------------------*/
#include <NDS/NDS.h>
#include <NDS/DMA.h>
#include <NDS/ARM9/trig_lut.h>
#include <NDS/ARM9/math.h>
#include <NDS/ARM9/video.h>
#include <NDS/ARM9/videogl.h>
#include <NDS/registers_alt.h>

/*--------------------
CLASSES
--------------------*/
class Unit {
public:
std::string name;

public:
Unit() {}
};

template<class T>
class UnitList : public std::list<T> {
public:
void IteratorDontWork() {std::list<T>::iterator it = begin();}
};

/*--------------------
GLOBALS
--------------------*/
UnitList<Unit> TheList;

/*----------------------------------------------
Function: main()
Purpose: Main Program Loop Entry Point
Inputs: None
Outputs: Exit Flag
----------------------------------------------*/
int main(int argc, char ** argv)
{
return 0;
}


When I attempt to compile I get this error: expected `;' before "it"
I'm beyond confused, it's probably just a simple schoolboy error but still i'm baffled. I'm currently running off NDSEnv 2.3.0 and running out of ideas and sanity.

Cheers

#43137 - Mr Snowflake - Thu May 19, 2005 12:33 pm

I'm not really into classes in C but I think you have a space to much no?
Code:
void IteratorDontWork() {std::list<T>::iterator it = begin();

#43139 - blaisef01 - Thu May 19, 2005 12:49 pm

Cheers Mr Snowflake. for the suggestion but that unfortunately that doesn't seem to be it or i'm an idiot and don't understand what you mean.

I tried out the same code in Visual C++ using the MFC libs and it compiles fine. Try it with all this devkitarm malarky and it doesn't want any of it :(

this compiles:
void IteratorDontWork() {std::list<char>::iterator it; it = this->begin();}

while this doesn't:
void IteratorDontWork() {std::list<T>::iterator it; it = this->begin();}

and it returns these errors:
error: expected `;' before "it"
error: `it' undeclared (first use this function)

why?

#43165 - Quirky - Thu May 19, 2005 7:06 pm

Code:

#include <list>

template<class T>
class UnitList : public std::list<T>
{
  public:
    void IteratorDontWork(){
      typedef typename std::list< T >::iterator iterator_t;
      iterator_t  t = this->begin();
    };
};

typedef UnitList<int> IntList;


I have no idea if this does what you want, but it seems to compile.

#43203 - blaisef01 - Fri May 20, 2005 7:19 am

That typedef typename stuff worked a treat.

Cheers dude,