1
class Test
2
{
3
public :
4
Test( int ) {}
5
Test() {}
6
void fun() {}
7
8
int i;
9
};
10
void main( void )
11
{
12
Test a(1);
13
Test b();
14
15
a.fun();
16
b.fun();
17
}
18
編譯信息:
2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

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();作為一個函數(shù)聲明對待了。
調(diào)用默認(rèn)的無參數(shù)的構(gòu)造函數(shù)來構(gòu)造對象應(yīng)該這樣定義:Test b;