테스트다뇨니

첫 테스트 글

아몬 께서 별빛 으로 속삭 이셨 다

그분은 핑구를 파괴한다고 하셨다

// C++98
#include <iostream>
#include <string>

// 아주 단순한 Pingu 타입
class Pingu {
public:
    explicit Pingu(const std::string& name) : name_(name) {
        std::cout << "[ctor] Pingu(" << name_ << ") created\n";
    }
    ~Pingu() {
        std::cout << "[dtor] Pingu(" << name_ << ") destroyed\n";
    }
    void beep() const {
        std::cout << name_ << ": noot noot!\n";
    }
private:
    std::string name_;
};

int main() {
    //1 핑구 파괴
    {
        Pingu p("stack-pingu");
        p.beep();
    } 

    //2 동적으로 핑구 파괴
    Pingu* heapPingu = new Pingu("heap-pingu");
    heapPingu->beep();
    delete heapPingu;

    //3 구닥다리로 핑구 파괴
    std::auto_ptr<Pingu> owned(new Pingu("pingu"));
    owned->beep();
    owned.reset(0);

    //4 배열로 핑구 대량 파괴
    Pingu* squad = new Pingu[2] { Pingu("pingu0"), Pingu("pingu1") };
    delete[] squad;

    return 0;
}
BGM 재생