hotmail:struct Foo
{
Foo() { cout << "before main" << endl;}
~Foo() { cout << "after main" << endl;}
};
一样可以的,但是析构函数的输出你是怎么看到的?
(发表于2004-12-16 8:21:00)
nscboy:#include
struct Foo
{
Foo() { printf("printf:before main()\n"); }
~Foo() { printf("printf:after main()\n"); }
};
struct Coo
{
Coo() { std::cout<<"cout:before main"< ~Coo() { std::cout<<"cout:after main"<};
Coo smallCoo;
Foo smallFoo;
int main(int argc, char* argv[])
{
std::cout << "Hello, world !\n";
return 0;
}
vc7输出:
cout:before main
printf:before main()
Hello, world !
printf:after main()
cout:after main
vc6sp输出:
cout:before main
printf:before main()
Hello, world !
printf:after main()
看来VC6输出的结果确实和VC7.1不一样
(发表于2004-12-16 11:35:00)
小扇子:nscboy兄,看你测试的情况就是说Coo 的析构函数最后居然没有被调用啊???这是为什么?????那位高手分析一下!
(发表于2004-12-17 10:25:00)
小扇子:哦,刚才没看仔细.我看了一下,其实析构函数是调用了,只是std::cout没有打印出字来.Foo用了printf就可以打印出来.
我以为这个不是C++语言的问题,而是VC6.0编译器的问题
(发表于2004-12-17 10:38:00)
flybus:我没有用过vc7.0,不过这个应该是和vc7.0的std::cout实现有关系,比如其用到的某个全局变量已经des掉了,所以打印不出来,而vc6可能实现又不同,so。。。
(发表于2004-12-19 22:22:00)
wuhuaqiang:没有意义的讨论啊。
各位使用vc6时,一定要打上sp5或更高版本的补丁,然后再看看结果。
(发表于2004-12-20 10:57:00)
谭詠麟:#include
//加这一句就可以用cout了
using namespace std;
struct Foo
{
Foo() { printf("printf:before main()\n"); }
~Foo() { printf("printf:after main()\n"); }
};
struct Coo
{
Coo() { std::cout<<"cout:before main"< ~Coo() { std::cout<<"cout:after main"<};
Coo smallCoo;
Foo smallFoo;
int main(int argc, char* argv[])
{
std::cout << "Hello, world !\n";
return 0;
}
(发表于2005-3-3 14:57:00)
..........................................................................
--------------------next---------------------