Solved

does anyone know why this is happening:

Posted on 2001-08-02
8
252 Views
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?
0
Comment
Question by:emily_hall
8 Comments
 
LVL 2

Expert Comment

by:Lockias
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;

~Lockias
0
 
LVL 86

Expert Comment

by:jkr
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
0
 
LVL 2

Expert Comment

by:Lockias
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".
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 1

Author Comment

by:emily_hall
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...


0
 

Expert Comment

by:CTrip
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
   mistake
0
 
LVL 2

Expert Comment

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

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

Accepted Solution

by:
Lockias earned 100 total points
ID: 6346620
emily,
  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;

~Lockias
0
 
LVL 1

Author Comment

by:emily_hall
ID: 6346652
woohoo!  it works!  thanks!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

786 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