Error: C2228: left of '' must have class/struct/union

后端 未结 4 1088
南旧
南旧 2020-12-08 14:53

I\'m a long time Java user learning C++ with Qt and I\'m having a lot of trouble understanding how methods work. Right now, I\'m trying to figure out databases, and tried to

相关标签:
4条回答
  • 2020-12-08 15:14

    In support to the accepted answer.

    From dcl.init#11:

    An object whose initializer is an empty set of parentheses, i.e., (), shall be value-initialized.

    [ Note: Since () is not permitted by the syntax for initializer,

    X a();
    

    is not the declaration of an object of class X, but the declaration of a function taking no argument and returning an X. The form () is permitted in certain other initialization contexts ([expr.new], [expr.type.conv], [class.base.init]). — end note ]

    0 讨论(0)
  • 2020-12-08 15:17

    You need to say this:

     DatabaseControl myDBControl;
     myDBControl.addEmployee();
    
    0 讨论(0)
  • 2020-12-08 15:22

    You made an error here:

    DatabaseControl myDBControl();
    

    You declared a function called myDBControl taking no arguments and returning a DatabaseControl.

    Object declarations without any constructor arguments must omit the ():

    DatabaseControl myDBControl;
    

    This is related to (but is not precisely) the "most vexing parse", in that it's caused by the same language rule that statements are function declarations if they can be so parsed.

    0 讨论(0)
  • 2020-12-08 15:38
    DatabaseControl myDBControl();
    

    should be

    DatabaseControl myDBControl;
    
    0 讨论(0)
提交回复
热议问题