Hi
I wrote a Singleton class but i got an error while controlling instantiation
captain.h
#ifndef CAPTAIN_H
#define CAPTAIN_H
#include <iostream>
#include <string>
class Captain
{
private:
Captain();
Captain(const Captain&);
Captain &operator=(const Captain&);
std::string name;
public:
//Controll Instantiation
static Captain &GetInstance();
//Set Name of the Captain
std::string GetName();
//Get his/her name
void SetName(std::string _name);
};
#endif // CAPTAIN_H
captain.cpp
#include "captain.h"
Captain& Captain::GetInstance(){
static Captain instance; //The Error redirect me to here.
return instance;
}
std::string Captain::GetName(){
return name;
}
void Captain::SetName(std::string _name){
name = _name;
}
main.cpp
#include <iostream>
#include "captain.h"
int main()
{
Captain &Club = Captain::GetInstance();
Club.SetName("Sarbast");
std::cout<<Club.GetName()<<std::endl;
return 0;
}
Error
error: undefined reference to `Captain::Captain()'