0
#include <iostream>


using namespace std;

 class A{
public:
    A(){
    cout << "Class A!";}
    };


 int main()
{
    A a();
}

the above code does not call the constructor A :: A() even though they have the same input parameters (none). however if, in the main function, I remove the parenthesis from A a(); it calls the constructor. so what is the difference between A a; and A a();

i believe the question here is very similar maybe even the same however if some could explain in simpler terms I would be very grateful. Do the parentheses after the type name make a difference with new?

would declaring A a(); ever call a constructor, under any circumstances?

do parameterless constructors exist in c++, or is that the same as a default constructor?

simbaDude
  • 5
  • 2

1 Answers1

1

With

A a();

you declare a as a function taking no arguments and returning an A object.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621