#include <iostream>
using namespace std;
class characterControl {
private:
//생성자, 복사생성자, 대입연산자, 소멸자 모두 private에 생성해 다른 어떠한 방법으로도 객체 생성을 막음
characterControl() { }
characterControl(characterControl& c) { }
characterControl operator= (characterControl& c) { }
~characterControl() { }
int x = 0, y = 0;
public:
static characterControl& getControl() { //유일하게 객체 얻을 수 있는 정적 멤버 변수로 참조값으로 반환함
static characterControl useCharacter; // 객체 생성
return useCharacter; // 객체 반환
}
void CharacterMove(int x, int y) {
this->x += x;
this->y += y;
}
void Show() {
cout << "현재 플레이어의 위치 x : " << x << ", y : " << y << endl;
}
};
int main()
{
bool isPlaying = true;
int x = 0, y = 0;
characterControl& myCharacter = characterControl::getControl();
characterControl& other = characterControl::getControl();
cout << &myCharacter << endl; // 주소값 확인용
cout << &other << endl;
other.Show();
myCharacter.CharacterMove(10, 10);
other.Show();
}
참조로 객체생성한걸 반환 받아서 사용하는데, 객체 1개만 생성되어서 싱글턴이라 볼 수 있나요?
아님 다른 이름으로 참조를 받아서 사용해서 싱글턴이라 볼 수 없나요?

두 참조로 받은 객체 모두 주소가 같고 값 변경도 같은거 보면 객체 생성은 1개만 된건 맞는거 같네요