# declaring a std:vector inside of a struct ?

## Recommended Posts

I have a simple compile problem. I try to do this: typedef struct STest { .... vector<int> vFrameTimes; ... } STest; But I get the compile error: error C2143: syntax error : missing ';' before '<' error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C2238: unexpected token(s) preceding ';' I'm using the std namespace.. and when changing the syntax to std::vector<int> vFrameTimes I get the additional error error C2039: 'vector' : is not a member of 'std' I have no problems using vectors nor struct elsewhere in the program. What should I do to make my code working?

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

But seriously, post your real code. It's impossible to say from the little that you've given us.

##### Share on other sites
Quote:
 error C2143: syntax error : missing ';' before '<'error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

This generally means that the compiler doesn't know that vector is a template-type class, which would mean that the compiler doesn't know what the vector class is. My guess is that you forgot to #include<vector>

EDIT:
Ninja'd [smile]

##### Share on other sites
Quote:
 Original post by WhiteCoffeetypedef struct STest{....vector vFrameTimes;...} STest;

C++ version:
#include <vector>struct STest {  std::vector<int> vFrameTimes;};

##### Share on other sites
Mike.Popoloski -> Didn't wan't to include the code because of program complexity.

Well, I solved the problem. The problem was file dependencies, I didn't include the proper header-files, so the vector was unknown for the compiler, as _fastcall mentioned.

##### Share on other sites
If your problem is too complex to post, that's your first hint that you haven't done everything you could on your own to solve it. Reducing your program down until you have a reliable test case will help you catch a whole range of problems on your own, and if by the time you're done you still can't figure out what's wrong, it will be easy to post what you have to let others help you.

##### Share on other sites
Mike.Popoloski ->
Well, it's not too complex in a scense that I don't understand the program, but just posting the whole code would seem stupid since most of the code would have been irrelevant. Of course I could have tried solving it in greater detail on my own before posting, and reduced it to a smaller test sample.

But in this case choosed to rather rush making the forum post in case there was some obvious incompability with structs/template classes that I didn't know about, since i'm not an C++ expert. By doing this I could have catched an, for others than me, obvious mistake before spending too much time debugging.

I'm sorry if this upset you, but appearently I got the help I needed by doing like this.

##### Share on other sites
You got the help - but did you learn from the experience?

I would see it as time invested, not wasted. Reducing the problem to its simplest form is an important skill. No one expects you to be a C++ expert, but we would expect some independant attempt at solving the problem.

##### Share on other sites
Why do you blame him? He did reduce the code on its own up to 3 lines of code where the problem was very clear; what better could he do?

##### Share on other sites
Quote:
 Original post by NyarlathWhy do you blame him? He did reduce the code on its own up to 3 lines of code where the problem was very clear; what better could he do?

His code is not a complete working (working as in demonstrating the error) example. Since there are code that he left out, the source of the problem could have in the parts he left out.

The problem in this case wasn't in the code he posted, but in the code he left out. He never include the correct header file, and that was never apparent from the code he posted.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628377
• Total Posts
2982324

• 10
• 9
• 14
• 24
• 11