does anyone know why this is happening:

Posted on 2001-08-02
Last Modified: 2011-10-03
i have a class that includes vector.h as a header file but when i have a vector declaration like this:

vector<_variant_t, _variant_t> m_myVariable it gives this error:

error C2143: syntax error : missing ';' before '<'

i tried commenting everything out of the file except for the include and the line

vector a;

same error

i tried commenting everything out except the line

vector<int> a;

same error.

what is going on with this thing?
Question by:emily_hall
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 6345921
Your include statement needs to look like this:
#include <vector>

Then you can either put this after it:
using namespace std;

or, declare like this:
std::vector<_variant_t, _variant_t> m_myVariable;

LVL 86

Expert Comment

ID: 6345923
>>what is going on with this thing?

>>i have a class that includes vector.h

You'll have to

#include <vector> // NOTE: No .h extension

using namespace std; // use the standatd namespace

Expert Comment

ID: 6345928
To make a long story very short, vector.h is not a part of standard c++.  The standard includes do not have the ".h".
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 6346078
ok thanks - but now i am getting this as an error:

c:\program files\microsoft visual studio\vc98\include\vector(24) : error C2039: 'size_type' : is not a member of 'CRecord'

that is with my declaration like this:

vector<_variant_t> m_myVariable

the size_type is something that is declared as being part of vector...


Expert Comment

ID: 6346574
To make a long story very short, vector.h is not a part of standard c++.  so the include should look like that:
#include "vector.h"

now, for the constructor:
  you shold look at the vector.h file and see
  what kind of constructor it have.
  if it's the regular constructor, the declaration should
  look like that:
  vector myVector(a,b);

  and if you will write:
  vector<_variant_t, _variant_t>
  what is that "<" ?
  the Compiler will think that it should be
  "vector;" and the "<_variant_t, _variant_t>" it's a

Expert Comment

ID: 6346601
  Yes, it should be #include <vector> (NO .h!)

  And vector is a template.  The "< >" is how your parameterize a template when you instantiate it.

Accepted Solution

Lockias earned 100 total points
ID: 6346620
  Are you sure your declaration is not
  vector<_variant_t, _variant_t> m_myVariable;

  It looks for the member size_type on the second parameter you in the list.  If you only pass one parameter, such as in
  vector<_variant_t> m_myVariable;
then the second parameter defaults to allocator<T>, where T is the first parameter you pass.  This *should* work.

Also, make sure that you are not somewhere in the include chain including <vector.h>.  It you are or are not, it would not hurt to do this
  std::vector<_variant_t> m_myVariable;


Author Comment

ID: 6346652
woohoo!  it works!  thanks!

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question