cpp_Fiasco - 8BitsCoding/RobotMentor GitHub Wiki
Fiasco
๋ค์ ์ฝ๋์ ๋ฌธ์ ์ ์ด ๋ญ๊น?
// Dog, Cat์ ๋ค๋ฅธ๋ฐ ๊ตฌํํ๊ณ ...
using namespace std;
Dog d("Gunner");
int main() {
d.bark();
return 0;
}
// Dog.cpp
Cat c("Smokey");
Dog::Dog(char name) {
std::cout << "Constructing Dog " << name << std::endl;
_name = name;
c.meow();
}
๋ฌธ์ ๊ฐ ๋ญ๊น?
Dog์ ์์ฑ ์์ ๋ณด๋ค Cat์ ์์ฑ์์ ์ด ๋๋ฆด ๊ฒฝ์ฐ ํ๋ก๊ทธ๋จ์ด ์ฃฝ๊ฒ ๋๋ค.
ํด๊ฒฐ๋ฐฉ๋ฒ? :
Singleton Patern ์ด์ฉ
class Dog;
class Cat;
class Singleton {
static Dog* pd;
static Cat* pc;
public:
~Singleton();
static Dog* getDog();
static Cat* getCat();
};
int main() {
Singleton s;
s.getCat->meow();
}