static variable link error [duplicate]
You must define the statics in the cpp
file.
Log.cpp
#include "Log.h"#include <ostream>string Log::theString; // <---- define static herevoid Log::method(string arg){ theString = "hola"; cout << theString << endl; }
You should also remove using namespace std;
from the header. Get into the habit while you still can. This will pollute the global namespace with std
wherever you include the header.
You declared static string theString;
, but haven't defined it.
Include
string Log::theString;
to your cpp
file