posts - 134,comments - 22,trackbacks - 0
 1class Test
 2{
 3public :
 4    Test( int ) {}
 5    Test() {}
 6    void fun() {}
 7
 8    int i;
 9}
;
10void main( void )
11{
12    Test a(1);
13    Test b();
14
15    a.fun();
16    b.fun();
17}

18
编译信息:

--------------------Configuration: hex - Win32 Debug--------------------
Compiling...
hex.cpp
E:\Projects\C++\Hex\hex.cpp(42) : error C2228: left of '.fun' must have class/struct/union type
Error executing cl.exe.

hex.exe - 1 error(s), 0 warning(s)

结论:
也就是说Microsoft C++编译器把Test b();作为一个函数声明对待了。
调用默认的无参数的构造函数来构造对象应该这样定义:Test b;
posted on 2010-05-19 20:41 何克勤 阅读(309) 评论(0)  编辑  收藏 所属分类: C/C++

只有注册用户登录后才能发表评论。


网站导航: