Hey I'm trying to create a singleton class and I've come across unresolved token and unresolved external symbol errors whenever I include the Server.h file in Form1.h and try to call CreateSingleInstance. Could someone please help me understand why these errors occur? Any type of help is much appreciated =].
//Server.cpp
#include "stdafx.h"
#include "Server.h"
Server::Server(int port) : _port(port) { }
void Server::Start()
{
MessageBox::Show("Start Called");
}
void Server::Stop()
{
MessageBox::Show("Stop Called and port = " + Int32(this->_port).ToString());
}
Specifically the errors read:
1 2
error LNK2020: unresolved token (0A00004D) "public: static class Server * Server::s_instance"(?s_instance@Server@@$$Q2PAV1@A)
error LNK2001: unresolved external symbol "public: static class Server * Server::s_instance" (?s_instance@Server@@$$Q2PAV1@A)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// Form1.h
#pragma once
#include "Server.h"
namespace ChatServer {
...
public ref class Form1 : public System::Windows::Forms::Form
{
...
private: System::Void btnServerStart_Click(System::Object^ sender, System::EventArgs^ e) {
this->btnServerStop->Enabled = true;
this->btnServerStart->Enabled = false;
Server* s = Server::CreateSingleInstance(31337); // Error when adding this
}