Wednesday 10 June 2009

Difference between MyClass p; and MyClass p();

Sometimes there are interesting questions asken in an interview. I am going to add some of them when I come across under the 'Interview Questions' tag.

So, what is the difference between MyClass p; and MyClass p();?

MyClass p; creates an instance of class MyClass by calling a constructor for MyClass.

MyClass p(); declares function p which takes no parameters and returns an object of class MyClass by value.

No comments:

Post a Comment