繁体   English   中英

错误:没有与构造函数初始化调用的匹配函数

[英]error: no matching function for call to with constructor initialization

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: 错误:在 '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>
using namespace std;

namespace ns{

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

暂无
暂无

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

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