Other Help Topics :: help on a c++ program



Hi,
I'm trying to write a small program that works with a collection of objects in c++ on a rh8.0 box. I got the objects but I can't create the collection.
I reduced the program to the simplest possible code but I'm still getting the same errs.
This is the file a.cpp:

/******start********/
#include <list>

main()
{
  list<int> L;
  return 0;
}

/*****end*******/

and this are the errs:

#gcc a.cpp -o a.cgi
a.cpp: In function `int main()':
a.cpp:5: `list' undeclared (first use this function)
a.cpp:5: (Each undeclared identifier is reported only once for each function it
  appears in.)
a.cpp:5: parse error before `>' token

the file 'list' exists in the include directory.
any ideeas?

Lii, watch out for the namespace!  Try adding a using namespace std; line and compile it using g++ NOT gcc since it's a c++ program.

Code Sample
#include <list>

using namespace std;

main(){
  list<int> myList;
 myList.push_back (5);
 myList.push_back (6);
 myList.push_front (7);
}


g++ test.cpp -o mytest

10x a lot! it compiles superbly now :D

I should study more about those namespaces  ???


original here.