다음 코드는 1, 2, 3을 인쇄합니다. 그것은 모든 C++ 컴파일러가 원했던 것과 사실입니까?왜 명명되지 않은 C++ 객체가 범위 블록이 끝나기 전에 파괴됩니까?
class Foo
{
const char* m_name;
public:
Foo(const char* name) : m_name(name) {}
~Foo() { printf("%s\n", m_name); }
};
void main()
{
Foo foo("three");
Foo("one"); // un-named object
printf("two\n");
}
복제본 : http://stackoverflow.com/questions/1388685/local-variable-scope-question –