Unresolved Token and External Symbol in my class

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 =].

Thanks,
Mack

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Server.h
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

public class Server
{
public:
	Server(int port);
	static Server* s_instance;

	static Server* CreateSingleInstance(int port)
	{
		if ( !s_instance )
			s_instance = new Server(port);
		return s_instance;
	}

	void Start();
	void Stop();

private:
	int _port;
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//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
		 }
Last edited on
You didn't define s_instance ( you only declared it )
Wow, thanks a ton! =D
Topic archived. No new replies allowed.