Re: help on using <list> <vector> in a simple VC program by Igor
Igor
Tue Apr 11 15:20:23 CDT 2006
kuiyuli@gmail.com wrote:
> I'm using VC++ .Net to do a simlple program. I tried to use <vector>,
> <list> in the program, and I simply put the folowing lines
> "
> #include <list>
> #include <vector>
> #include <string>
> using namespace std;
> .....
> vector <int> list;
>
> in the head part of my file "simple.h".
First, you should not define variables in the header file, otherwise
you'll likely get linker errors since every source file that includes
your header gets a copy of the variable. Do it this way:
// in .h file
extern vector<int> myList;
// in exactly one .cpp file
vector<int> myList;
Second, it's probably not a terribly good idea to give a variable the
same name as a class (I'm talking about 'list'). I don't think it should
produce an error, but it's likely to create confusion.
> But it gives compilation error
> when I try to compile it in "Debug" mode, but it's ok in the "Release"
> mode.
Quote the exact error text, and show the line of code it refers to. I
seem to have misplaced my crystal ball.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925