简体   繁体   English

C ++没有适当的默认构造函数

[英]C++ No appropriate default constructor

I know this has been asked before, but I can't find the problem on my code. 我知道之前已经有人问过这个问题,但是我在我的代码中找不到问题。 It's a fairly simple code, I have checked and the class Point works perfectly ( it has a default value of (0,0) ), though the Circle one isn't 这是一个非常简单的代码,我已经检查过,并且Point类可以正常工作(其默认值为(0,0)),尽管Circle 1不是

 class Circle{
public:
    Circle(Point, double);
    Circle(const Circle& c);
    ~Circle();
    void setCenter(Point scenter);
    void setRadius(double sradius);
    double getSurface();
    Point getCenter() const;
    double getRadius() const;
    void print() const;

private:
    Point center;
    double radius;
};

Circle::Circle(Point c, double r)
{
    r = 1.0;
    setCenter(c);
    setRadius(r);
}

What am I doing wrong? 我究竟做错了什么?

A default constructor is only generated for you if you have no other constructors. 如果没有其他构造函数,则仅为您生成默认构造函数。 If you want to have a default constructor (ie, no arguments) in addition to constructors with arguments, you need to define it 如果除了带有参数的构造函数之外,如果还想要默认的构造函数(即,没有参数),则需要对其进行定义

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM