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".
Industry Leaders: 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

738 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