Search code examples
c++default-constructor

C++ default constructor: string params vs string params()


Possible Duplicate:
Is no parentheses on a constructor with no arguments a language standard?

Can anyone explain why these line don't give me an error:

string params;
params+="d";

but these lines:

string params();
params+="d";

give me this error: error C2659: '+=' : function as left operand


Solution

  • This is not object:

     string params();
    

    This is function returning string:

     string params();
    

    Like this:

     string params(void);
    

    So the error now is obvious: function as left operand

    This problem has own name: http://en.wikipedia.org/wiki/Most_vexing_parse