• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Help with initializing a vector

## Recommended Posts

CPattern is just a plane generic class in my other class i define the vector like so vector m_Patterns; I get this error error C2143: syntax error : missing '';'' before ''<'' error C2501: ''CPatternController::vector'' : missing storage-class or type specifiers error C2238: unexpected token(s) preceding '';'' it doesn seem to recognize and i havent done a vector in 6 months i would think it would be vector m_Patterns; please help I need the correct initialization. thanks, nick

##### Share on other sites
These errors are a bit difficult to debug without the code in front of us to tweak with, but it sounds as though it doesn''t know what a vector is. You did make sure to include <vector>, right?

##### Share on other sites
i used #include <vector>

I searched for vector.h and it doesn''t exist on my computer, can I get it somewhere

the code I gave is the only code in the file other than the contructor and destructor which have nothing in them

##### Share on other sites
i tried these

vector m_Patterns;

and

vector m_Patterns and the same errors

##### Share on other sites
greater than and less than signs are in there but donbt show up

##### Share on other sites
well, i think u need to specify the data type that the vector is gonna store. the STL uses templates. so ur code shud be:

  vector<datatype> m_Patterns;

[edited by - crazee on May 8, 2003 12:17:07 PM]

##### Share on other sites
To initialize a vector you need to specify the data type also, i.e. u need to tell the compiler what kind of data the vector will store.

For e.g.

     #include <vector>   .   .   .   vector <int> NumVector;   .   .   .

In the above example a vector NumVector of type "int" will be created.

in the same way you must give...

    vector  m_Patterns;

"There is a Bug in every Code!"

##### Share on other sites
There was a error in my previous post.
this is the corrected one...

To initialize a vector you need to specify the data type also, i.e. u need to tell the compiler what kind of data the vector will store.

For e.g.

     #include <vector>   .   .   .   vector <int> NumVector;   .   .   .

In the above example a vector NumVector of type "int" will be created.

in the same way you must give...

      vector <your_data_type> m_Patterns;

"There is a Bug in every Code!"

try using
std::vector
vector

##### Share on other sites
You can use &lt; and &gt; to create the less than and greater than symbols respectively.

The first way you declare the vector is incorrect, unless you are passing your own allocator. here for details.

The problem is that the vector class is under the std namespace in the standard headers. To use it, you can do one of three things:

At the top of the module, either:
using namespace std;
or
using std::vector;

Or you can simply prefix std:: wherever you use a vector:

std::vector <CPattern> m_Patterns;

##### Share on other sites
thank you very much, it works now

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627678
• Total Posts
2978605

• 12
• 12
• 10
• 12
• 22