Skip to main content
GameDev.net gamedev.net
🔒 Locked

the standard vector class

Started by flucknugget Apr 21, 2002 at 12:03 AM 2 replies 200+ views
Original Post
flucknugget
flucknugget
I was searching for a standard vector class that I could use so I wouldn''t have to write my own, and MSDN told me about #include <vector>. I want to have a vector of BITMAP pointers, so I did this:
typedef vector<BITMAP*, allocator<BITMAP> > BITMAPVECT;
BITMAPVECT frames; 
When I try compiling this the compiler gives me these 6 errors for every source file in my project: c:\code\msvc\escape\anim.h(30) : error C2143: syntax error : missing '';'' before ''<'' c:\code\msvc\escape\anim.h(30) : error C2059: syntax error : ''<'' c:\code\msvc\escape\anim.h(30) : error C2238: unexpected token(s) preceding '';'' c:\code\msvc\escape\anim.h(31) : error C2146: syntax error : missing '';'' before identifier ''frames'' c:\code\msvc\escape\anim.h(31) : error C2501: ''BITMAPVECT'' : missing storage-class or type specifiers c:\code\msvc\escape\anim.h(31) : error C2501: ''frames'' : missing storage-class or type specifiers - f l u c k y p o o - the geek inside
- f l u c k y p o o
IndirectX
IndirectX
STL things are declared in std namespace. Use

std::vector Blah;

or

using namespace std;
vector Blah;

Also, your allocator <BITMAP> part seems strange to me. Are you sure that you didn't mean std::allocator <BITMAP *>? If so, your compiler should be able to provide that template parameter by default.

[edited by - IndirectX on April 21, 2002 1:31:13 AM]
---visit #directxdev on afternet <- not just for directx, despite the name
flucknugget
flucknugget
After searching MSDN a lot more, I managed to find an example of a vector being used.


  #include <vector>
#include <iostream.h>

typedef vector<int, allocator<int> > INTVECT;
void somefunct()
{
// declare an INTVECT with slots for 10 ints

INTVECT myVector(10);
int i;

for(i = 0; i < 10; i++) // fill myVector with the values 0 - 9

myVector[i] = i;

for(i = 0; i < 10; i++) // print the values in myVector

cout << myVector[i] << ", ";
cout << endl;
}

void main()
{
somefunct();
}


Only, when I compile it I get these errors:

Compiling...
main.cpp
c:\code\msvc\test\main.cpp(4) : error C2143: syntax error : missing '';'' before ''<''
c:\code\msvc\test\main.cpp(4) : error C2143: syntax error : missing '';'' before ''<''
c:\code\msvc\test\main.cpp(8) : error C2065: ''INTVECT'' : undeclared identifier
c:\code\msvc\test\main.cpp(8) : error C2146: syntax error : missing '';'' before identifier ''myVector''
c:\code\msvc\test\main.cpp(8) : error C2065: ''myVector'' : undeclared identifier
c:\code\msvc\test\main.cpp(12) : error C2109: subscript requires array or pointer type
c:\code\msvc\test\main.cpp(12) : error C2106: ''='' : left operand must be l-value
c:\code\msvc\test\main.cpp(15) : error C2109: subscript requires array or pointer type
Error executing cl.exe.

test.exe - 8 error(s), 0 warning(s)

After some more extensive searching, I found stuff on library files to add to be linked. It says to add LIBCD.LIB for the Basic C run-time library, LIBCPD.LIB for the Standard C++ Library, and LIBCID.LIB for the old iostream library. If I link any of these with my project, it still doesn''t work. Any ideas?


- f l u c k y p o o
- the geek inside
- f l u c k y p o o
flucknugget
flucknugget
quote:
Original post by IndirectX
STL things are declared in std namespace. Use

std::vector Blah;

or

using namespace std;
vector Blah;

Also, your allocator part seems strange to me. Are you sure that you didn''t mean std::allocator ? If so, your compiler should be able to provide that template parameter by default.

[edited by - IndirectX on April 21, 2002 1:31:13 AM]


Yeah, I did mean BITMAP*. Thanks, ok, that works now.


- f l u c k y p o o
- the geek inside
- f l u c k y p o o

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.