Using singleton in c++

I created following classes in my program.

Way.h

1
2
3
4
5
6
7
8
9
10
11
12
class Way {
private:
    std::string id;
    std::string name;
public:
    Way();
    Way(const Way& orig);
    void SetName(std::string name) { this->name = name; }
    std::string const & GetName() const { return name; }
    void SetId(std::string id) { this->id = id; }
    std::string const & GetId() const { return id; }
};


way.cpp

1
2
3
4
5
#include "Way.h"
Way::Way() {
}
Way::Way(const Way& orig) {
}


AreaDataRepository.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class AreaDataRepository {
private: 
    Way onGoingWay;
public:
    AreaDataRepository();
    AreaDataRepository(const AreaDataRepository& orig);
    ~AreaDataRepository();
    static AreaDataRepository & Instance()
    {
        static AreaDataRepository singleton;
        return singleton;
    }
    void SetOnGoingWay(Way onGoingWay)  { this->onGoingWay = onGoingWay;  }
    Way const & GetOnGoingWay() const { return onGoingWay; }
};


AreaDataRepository.cpp

1
2
3
4
5
6
7
8
#include "AreaDataRepository.h"
#include "../common/Common.h"
AreaDataRepository::AreaDataRepository() {
}
AreaDataRepository::AreaDataRepository(const AreaDataRepository& orig) {
}
AreaDataRepository::~AreaDataRepository() {
}


in program main method

1
2
3
4
5
6
Way wayNode
wayNode.SetId("1234");
wayNode.SetName("jan");
AreaDataRepository::Instance().SetOnGoingWay(wayNode);
std::cout<<"Id ->>>>>>>>>>>>>" <<AreaDataRepository::Instance().GetOnGoingWay().GetId() << std::endl;
std::cout<<"Name ->>>>>>>>>>>>>" <<AreaDataRepository::Instance().GetOnGoingWay().GetName() << std::endl;


but this print nothing and i try to debug and get the values, vales are empty for OnGoingWay.
I need some help to sort out this.
thanks in advance!
1
2
3
4
Way::Way(const Way& orig) {
}

void SetOnGoingWay(Way onGoingWay) //invoke the copy constructor for Way  
Topic archived. No new replies allowed.