class problem

I have simple class here:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class utest
{
public:
	utest();
	~utest();
};

utest::utest()
{
	cout << "init" << endl;
}

utest::~utest()
{
	cout << "end" << endl;
}


now doing this:
1
2
3
4
5
6
void main()
{
    utest a();
    utest *b = new utest();
    delete b;
}


what do i expect to see is:
1
2
3
4
init
init
end
end

well, yea thats not happening but if i do:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class utest
{
public:
	utest(int a);
	~utest();
};

utest::utest(int a)
{
	cout << "init:" << a << endl;
}

utest::~utest()
{
	cout << "end" << endl;
}

void main()
{
    utest a(0);
    utest *b = new utest(0);
    delete b;
}


I do get what i expected.
Is that compiler error or is there something i don't know?
why class named function have to have param in order to get call?
Thanks!
The compiler will see utest a(); as a function declaration of a function named a that takes no arguments and has return type utest.
1
2
3
4
5
//Create variable a of type utest and initialize it using default constructor
utest a; 

//Declare function a, taking no arguments and returning utest by value
utest a();
Topic archived. No new replies allowed.