【发布时间】:2020-04-02 08:33:46
【问题描述】:
d.cpp 文件:
#include "file.hpp"
#include <iostream>
using namespace std;
int main() {
ns::T t ("ssssss");
}
文件.hpp
using namespace std;
namespace ns{
struct T{
T(string s);
};
};
为什么会出现这个错误?:
file.hpp:8:20: error: 's' T(string s) 之前的预期')';
d.cpp:在函数“int main()”中:d.cpp:14:26:错误:没有匹配 调用‘ns::T::T(const char [6])’ns::T t ("ssssss")的函数; 在 d.cpp:8 中包含的文件中:file.hpp:6:12: 注意:候选人: ‘constexpr ns::T::T()’ struct T{
【问题讨论】:
-
你的
#include <string>呢? -
每当您遇到此类小文件的问题时,不要使用
#include,只需复制粘贴代码并让您的 IDE 为您自动格式化,100% 您会立即看到问题。
标签: c++ constructor