please answer

suppose we have this class

class A
{
int k;
public:
A(int p=0):k(p) {}
};

is there any difference between A a and A a(); the " k " may be removed ...
Yes. One creates an object, the other prototypes a function.
i don't think so ..... i wrote

int main()
{
A a;
A b();
}

and it compiled just fine
And how does that disprove what Disch said?
Disch is correct. The fact that it compiles does not mean that A b(); isn't a prototype of a function. The reason it compiles is because you never actually call the function. Microsoft Visual C++ 2010 Express compiles it but gives the following warning:

A b(void)': prototyped function not called (was a variable definition intended?)


This is one of the idiosyncrasies of C++ syntax where one would expect that A b(); would call A's default constructor for b, but it does not. To instantiate using the default constructor leave off the parentheses A b;, otherwise the compiler will treat it as a function prototype.
And that's exactly why we have the new initializer syntax with C++11.
Topic archived. No new replies allowed.