I am mainly a C# programmer but I need this project done in C++ so I may be missing something for C++ arrays.
I have a DLL I have been working on, witch is working and connected into the project that handles the User Interface. In the DLL I am trying to make a logger class so I can debug info out into the interface. But when I try using a string array I get a LNK2001 error. Bellow is my header file for the class.
#include <string>
using namespace std;
class Logger
{
public:
static string& GetLog();
static void Log(string message);
private:
static const int maxLogs = 1000;
static string logs[maxLogs];
};
IF I remove the string array the error is gone but I need a way to store my log messages
The static
member variable must be defined (exactly once), that is only a declaration within the class defintion. In exactly one .cpp
file add:
std::string Logger::logs[Logger::maxLogs];
Suggest reading Why is "using namespace std" considered bad practice?