Sign in to follow this  
WhiteCoffee

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Nyarlath
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?

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this