简体   繁体   中英

error: no matching function for call to with constructor initialization

d.cpp file:

#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);

    };
    };

Why do I get this errors?:

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{

You need to include "string":

#include <string>
using namespace std;

namespace ns{

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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