error C2512: no appropriate default constructor available

后端 未结 4 1708
栀梦
栀梦 2021-01-17 09:26

I am getting this annoying error and I don\'t know why =( ! This is the question , I solved it but I am having a problem with the constructor.

Write a

相关标签:
4条回答
  • 2021-01-17 10:06

    Well, then add one :)

    Circle() : radius(0.0) {}
    
    0 讨论(0)
  • 2021-01-17 10:19

    This line invokes a constructor with no arguments (known as default constructor):

    Circle C;
    

    The only constructor you have defined is:

    Circle(double);
    

    Hopefully this should point you in the right direction.

    0 讨论(0)
  • 2021-01-17 10:24

    A default constructor is one without any parameters. Normally, it is provided for you. But if you explicitly define any other constructor, then it is not. So you have to define it yourself, or not use it. You are using it when you create an object in main, like this:

    Circle C;
    

    So, either define a default constructor, or don't use it.

    0 讨论(0)
  • 2021-01-17 10:28

    You should define a constructor with no parameters called default constructor. You can initialize related members to the default values.

    Circle::Circle()
       {
       radius = 0.0
       }
    
    0 讨论(0)
提交回复
热议问题