與克好奇東西++在棧上分配(也許還與其他編譯器):C++作用好奇
struct Object {
Object() { std::cout << "hey "; }
~Object() { std::cout << "hoy!" << std::endl; }
};
int main(int argc, char* argv[])
{
{
Object myObjectOnTheStack();
}
std::cout << "===========" << std::endl;
{
Object();
}
std::cout << "===========" << std::endl;
{
Object* object = new Object();
delete object;
}
}
Compied與克++:
===========
hey hoy!
===========
hey hoy!
第一種類型的分配的不構造對象。我錯過了什麼?
嘗試'對象myObjectOnTheStack;'即不帶'()' – Justicle 2010-02-18 23:28:57
@Jerry,感謝我糾正的術語 – JaredPar 2010-02-18 23:31:15
... 「而不是* *聲明的函數」 ... – Potatoswatter 2010-02-18 23:34:18