6
class A{
    private:
        string a;
    public:
        A():a("hello world"){};
        A(const string & arg):a(arg){};
        void put()const{cout<<a;};
};

A aaa();
A bbb;

So what's the difference between A aaa(); and A bbb; Is aaa a function?

CB Bailey
  • 755,051
  • 104
  • 632
  • 656
bitstore
  • 326
  • 2
  • 10
  • there is a 3rd option. calling constructor explicitly. A aaa = A(); – Rohit Vipin Mathews Feb 24 '12 at 08:46
  • possible duplicate of [Why is it an error to use an empty set of brackets to call a constructor with no arguments?](http://stackoverflow.com/questions/180172/why-is-it-an-error-to-use-an-empty-set-of-brackets-to-call-a-constructor-with-no) – CB Bailey Feb 26 '12 at 09:12

1 Answers1

11

Yes, the first one is interpreted as a function declaration. It's been called the Most Vexing Parse.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • 1
    `A aaa();` is not an example of the "most vexing parse". The most vexing parse refers to when you try to delcare an object and pass a value initializer temporary to all of its constructor parameters. e.g. `B c(D());` – CB Bailey Feb 26 '12 at 09:16