gpt4 book ai didi

c++ - 错误:没有匹配函数用于构造函数初始化的调用

转载 作者:行者123 更新时间:2023-12-02 10:04:22 26 4
gpt4 key购买 nike

d.cpp文件:

#include "file.hpp"

#include <iostream>
using namespace std;

int main() {
ns::T t ("ssssss");
}

file.hpp
using namespace std;


namespace ns{

struct T{

T(string s);

};
};

为什么会出现此错误?:

file.hpp:8:20: error: expected ‘)’ before ‘s’ T(string s);

d.cpp: In function ‘int main()’: d.cpp:14:26: error: no matching function for call to ‘ns::T::T(const char [6])’ ns::T t ("ssssss"); In file included from d.cpp:8: file.hpp:6:12: note: candidate: ‘constexpr ns::T::T()’ struct T{

最佳答案

您需要包括“字符串”:

#include <string>
using namespace std;

namespace ns{

struct T{
T(string s);
};
}

关于c++ - 错误:没有匹配函数用于构造函数初始化的调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60987322/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com