Jump to content
  • Advertisement
Sign in to follow this  
gapern

vector not recognizing its type?

This topic is 3614 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've got a vector off in it's own file and i'm filling it with objects of my thing class. Here's the entire header file. allthings.h
#ifndef ALLTHINGS_H
#define ALLTHINGS_H

#include "classes.h" //this is where my thing class is stored
#include "things.h" //this is where my objects of the thing class are stored
#include <vector>
#include <string>

using namespace std;

vector<thing> allthings;
allthings.push_back(tree1);
allthings.push_back(bush1);
allthings.push_back(crown);
allthings.push_back(separator);
allthings.push_back(tree2);
allthings.push_back(bush2);

#endif
Here are my errors.
error C2143: syntax error : missing ';' before '.'

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

error C2371: 'allthings' : redefinition; different basic types
Error #2 looks like it cannot recognize my thing class. But i've got that header file included. It's in classes.h. My objects are in things.h. Error #1 looks like it's related to error #2. Error #3 is weird. I do NOT have my allthings vector defined anywhere else in my code. All of my headers have inclusion guards also, so that shouldn't be the culprit. Note that these errors are repeated on every single push_back line. My vector DOES work if I have it in the file I want to use it in, which is adventure.cpp. But I have it in a separate file for a reason. I want to keep everything except the main game loop out of adventure.cpp. I'm assuming this has something to do with me needing a pointer somewhere, but I do not know where. Is it a pointer problem or is there something else that could be causing this? I have done everything I can think of and nothing has worked, so I really need some help here please.

Share this post


Link to post
Share on other sites
Advertisement
Not only that, but your compiler won't like it when ANY non-assignment statement is in global scope. If you could do things like this in global space, what would be the point of int main()?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!