I started learning C++ recently, and when trying some code on my own I got stuck in this problem tha I cant find the solution. I'm sure it's a simple thing, followed some advices from other questions but cant put this simple code to work.
I'm using visual studio 2013.
When compiling, I get the following error:
Error 1 error LNK2001: unresolved external symbol "public: static class std::vector,class std::allocator >,class std::allocator,class std::allocator > > > Config::myVector" (?myVector@Config@@2V?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@A) d:\User\andifar\documents\visual studio 2013\Projects\teste\teste\addItem.obj teste
Here's my header file:
#include <vector>
typedef std::vector <std::string> strVector;
class Config
{
public:
Config();
static void addItem();
static strVector myVector;
};
and my cpp file:
#include <vector>
#include "addItem.h"
Config::Config(){};
void Config::addItem(){
Config::myVector.push_back("Hi");
}
main:
#include "addItem.h"
int main(int argc, char** argv)
{
Config c;
c.addItem();
}