久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

沒有用于調(diào)用類構(gòu)造函數(shù)的匹配函數(shù)

No matching function for call to Class Constructor(沒有用于調(diào)用類構(gòu)造函數(shù)的匹配函數(shù))
本文介紹了沒有用于調(diào)用類構(gòu)造函數(shù)的匹配函數(shù)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在練習(xí)我的 OOP,我有以下課程:點和圓.具體來說,Circle 有一個中心點和一個半徑.相關(guān)代碼如下:

I am practicing my OOP and I have the following classes: Point and Circle. Specifically, Circle has a center Point, and a radius. Here is the relevant code:

// Point.h
class Point
{
    public:
        Point(double x, double y);
        double x() const;
        double y() const;
        std::string as_string() const;

    private:
        double x_coord;
        double y_coord;
};

// Circle.h
class Circle
{
    public:
        Circle(const Point& center, double radius);
        Point center() const;
        double radius() const;
        std::string as_string() const;
        std::string equation() const;

    private:
        Point center_pt;
        double radius_size;
};

// Circle.cpp
Circle::Circle(const Point& center, double radius)
{
    center_pt = center;
    radius_size = radius;
}

但是,當(dāng)我嘗試編譯此代碼時,出現(xiàn)以下錯誤:

However, when I try to compile this code, I get the following error:

Circle.cpp: In constructor ‘Circle::Circle(const Point&, double)’:
Circle.cpp:3: error: no matching function for call to ‘Point::Point()’
Point.h:10: note: candidates are: Point::Point(double, double)
Point.h:8: note:                 Point::Point(const Point&)

我不知道如何解釋這個錯誤.它是否告訴我需要在我的 Circle 構(gòu)造函數(shù)中為 Point 參數(shù)提供 x_coord 和 y_coord?

I am not sure how to interpret this error. Is it telling me I need to provide the x_coord and y_coord for the Point parameter in my Circle constructor?

推薦答案

成員 center_pt 被默認(rèn)初始化,這樣的操作將調(diào)用無參數(shù)默認(rèn)構(gòu)造函數(shù) Point().然而,這不是在 Point 類中定義的,因此會給你你得到的錯誤.

The member center_pt is being default initialized and such an operation will call the no arguments default constructor Point(). This however is not defined in the Point class and therefore gives you the error you got.

Circle::Circle(const Point& center, double radius)
{
    center_pt = center; //<-- this is an assignment
                        //default init has already occurred BEFORE this point
    radius_size = radius;
}

在您可以分配給 center_pt 之前,您需要先分配一些內(nèi)容.因此,在嘗試進(jìn)行賦值之前,編譯器會首先嘗試為您默認(rèn)初始化 center_pt.

Before you can assign to center_pt here you need something to assign to. The compiler therefore tries to default initialize center_pt for you first before trying to do the assignment.

相反,如果您使用成員初始值設(shè)定項列表,則可以避免以下問題默認(rèn)構(gòu)造后跟賦值:

Instead if you use the member initializer list you can avoid the problem of the default construction followed by assignment:

Circle::Circle(const Point& center, double radius):
    center_pt(center),
    radius_size(radius)
{
}

當(dāng)您創(chuàng)建一個類時,您實際上是在留出內(nèi)存來存儲該類中的各種成員.因此,將 center_ptradius_size 想象成內(nèi)存中的位置,這些值存儲在類的每個實例中.當(dāng)您創(chuàng)建一個類時,這些變量必須獲得一些默認(rèn)值,如果您沒有指定任何內(nèi)容,您將獲得默認(rèn)構(gòu)造值,無論這些值是什么.您可以稍后為這些位置分配值,但在創(chuàng)建類時總會進(jìn)行一些初始化.如果您使用初始化列表,您可以明確指定第一次放置在內(nèi)存中的內(nèi)容.

When you create a class you are essentially setting aside the memory to store the various members within that class. So imagine center_pt and radius_size as places in the memory that those values get stored in for each instance of your class. When you create a class those variables have to get given some default values, if you don't specify anything you get the default constructed values, whatever those are. You can assign values later to those locations but some initialization will always occur at the time of class creation. If you use the initializer list you get to explicitly specify what gets placed in the memory the first time around.

通過在此處使用成員初始值設(shè)定項列表,您的成員將在第一次被正確構(gòu)建.它還具有節(jié)省一些不必要操作的好處.

By using the member initializer list here your members are being constructed appropriately the first time around. It also has the benefit of saving some unnecessary operations.

這篇關(guān)于沒有用于調(diào)用類構(gòu)造函數(shù)的匹配函數(shù)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Assertion failed (size.widthgt;0 amp;amp; size.heightgt;0)(斷言失敗(size.width0 amp;amp; size.height0))
Rotate an image in C++ without using OpenCV functions(在 C++ 中旋轉(zhuǎn)圖像而不使用 OpenCV 函數(shù))
OpenCV: process every frame(OpenCV:處理每一幀)
Why can#39;t I open avi video in openCV?(為什么我不能在 openCV 中打開 avi 視頻?)
OpenCV unable to set up SVM Parameters(OpenCV 無法設(shè)置 SVM 參數(shù))
Convert a single color with cvtColor(使用 cvtColor 轉(zhuǎn)換單一顏色)
主站蜘蛛池模板: 91视频.com | 久久夜视频 | 日韩区 | 精品视频一区二区 | 亚洲高清网| 99精品亚洲国产精品久久不卡 | 国产无人区一区二区三区 | 日韩在线一区二区三区 | 美国一级片在线观看 | 国产乱码精品1区2区3区 | 天堂一区二区三区 | 国产91综合一区在线观看 | 天天拍夜夜爽 | 久久99精品久久久久久国产越南 | 九九精品在线 | 日韩中文在线 | 国产视频二区在线观看 | 日韩a在线观看 | 观看av | 成年免费大片黄在线观看一级 | 日韩成人免费视频 | 日韩精品一区二 | 亚洲 欧美 日韩 在线 | www网站在线观看 | 亚洲国产区 | 97人人超碰 | 欧美精品一区二区在线观看 | 成人做爰69片免费观看 | 欧美中文字幕一区二区三区亚洲 | 国内av在线 | 在线免费观看黄网 | 91成人精品| 精品国产黄a∨片高清在线 成人区精品一区二区婷婷 日本一区二区视频 | 黄色成人亚洲 | 日韩二区| 国产91黄色 | 国产在线视频一区二区 | 91视频在线观看 | 成人免费视频观看视频 | 精品国产31久久久久久 | 黄色免费网站在线看 |