Chinaunix首页 | 论坛 | 博客
  • 博客访问: 455022
  • 博文数量: 724
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 14:47
文章分类

全部博文(724)

文章存档

2011年(1)

2008年(723)

我的朋友

分类:

2008-10-13 17:23:14


#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)

没有意义的讨论啊。
各位使用vc6时,一定要打上sp5或更高版本的补丁,然后再看看结果。 ( wuhuaqiang 发表于 2004-12-20 10:57:00)

我没有用过vc7.0,不过这个应该是和vc7.0的std::cout实现有关系,比如其用到的某个全局变量已经des掉了,所以打印不出来,而vc6可能实现又不同,so。。。 ( flybus 发表于 2004-12-19 22:22:00)

哦,刚才没看仔细.我看了一下,其实析构函数是调用了,只是std::cout没有打印出字来.Foo用了printf就可以打印出来.
我以为这个不是C++语言的问题,而是VC6.0编译器的问题 ( 小扇子 发表于 2004-12-17 10:38:00)

nscboy兄,看你测试的情况就是说Coo 的析构函数最后居然没有被调用啊???这是为什么?????那位高手分析一下! ( 小扇子 发表于 2004-12-17 10:25:00)

#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不一样 ( nscboy 发表于 2004-12-16 11:35:00)

struct Foo 

Foo() { cout << "before main" << endl;} 
~Foo() { cout << "after main" << endl;} 
}; 
一样可以的,但是析构函数的输出你是怎么看到的? ( hotmail 发表于 2004-12-16 8:21:00)

.......................................................

--------------------next---------------------

阅读(237) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~