I'm trying to declare a vector as a global variable, and am getting a linker error. I read up on linker problems with multi-file projects, pretty sure I've included the proper headers, used extern, and #ifdef properly, but I can't get it yet. Here is what we have:
//in customclass.h
#ifndef _customclass
#define _customclass
class customclass {
private: int a;
public:
customclass() : a(0) {}
};
#endif
//in globals.h
#ifndef _globals
#define _globals
#include <vector>
#include "customclass.h"
extern std::vector <customclass> vectA;
#endif
//in globals.cpp
#include <vector>
#include "globals.h"
#include "customclass.h"
using namespace std;
vector <customclass> vectA(0);
vectA.reserve(30);
//in main.cpp
#include "customclass.h"
#include "globals.h"
#include <vector>
using namespace std;
cout << vectA.size() << endl;
Linker error cites unresolved symbol for vector customclass.
and the error goes away when I make it a vector of double or int.
Any ideas???
Thanks!