【问题标题】:Error E0289: No instance of constructor "Movie::Movie" matches the argument list for a Basic Program (C++)错误 E0289:没有构造函数“Movie::Movie”的实例与基本程序 (C++) 的参数列表匹配
【发布时间】:2019-12-12 09:04:41
【问题描述】:

我不知道为什么我会在这个基本程序上收到这个错误。我什至检查了代码并搜索了这个网站和谷歌的答案。我不明白如何解决我的错误。

链接:
E0289 : No instance of constructor "Phone::Phone" matches the argument list?
no instance of constructor matches the argument list
Error: No instance of constructor matches the argument list

这是我的代码:

#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
#include "trimdecimal.h"

using namespace std;

class Movie {
    public:
        string title;
        string director;
        string mainCast1;
        string mainCast2;
        int yearReleased;
        bool isAHit;
        int publicLikePercentage;
};

int main()
{
    Movie movie1 = Movie("Fast & Furious Presents: Hobbs & Shaw", "David Leitch", "Dwayne Johnson", "Jason Statham", 2019, true, 89);
}

正如我在标题中所说,我收到了这个错误:

E0289     no instance of constructor "Movie::Movie" matches the argument list

我在 Visual Studio 2019 上对此进行了编码

有什么解决办法吗?我将全心全意地感谢任何修复,但请具体说明并向我解释如何解决它,就像您对孩子所做的那样。

【问题讨论】:

  • 你在哪里有一个接受 7 个值作为参数的构造函数?实际上,你在哪里定义了任何构造函数?

标签: c++ visual-c++


【解决方案1】:

您尚未为 Movie 类定义将这些值作为参数的构造函数。

如果您尝试仅按成员初始化对象,请使用 {} 而不是 ()

Movie movie1 = Movie{"Fast & Furious Presents: Hobbs & Shaw", "David Leitch", "Dwayne Johnson", "Jason Statham", 2019, true, 89};

或者只是

Movie movie1 = {"Fast & Furious Presents: Hobbs & Shaw", "David Leitch", "Dwayne Johnson", "Jason Statham", 2019, true, 89};

【讨论】:

    猜你喜欢
    • 2021-12-10
    • 2013-10-29
    • 2016-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-02
    • 2019-03-27
    相关资源
    最近更新 更多