I\'m writing C++ code on a mac. Why do I get this error when compiling?:
Undefined symbols for architecture i386: \"Log::theString\", referenced f
You must define the statics in the cpp
file.
Log.cpp
#include "Log.h"
#include
string Log::theString; // <---- define static here
void 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.