社区!我正在尝试应用新的C++ 14功能,并在我尝试将const char []参数传递给下面给出的函数时意外遇到错误:
decltype(auto) autofunc( const auto& a)
{
cout<<"Hello World\n";
cout<<a<<endl;
}
auto lambd = [](const auto& word){ autofunc(std::forward< decltype(word) > (word));};
int main()
{
lambd("Goodbye World\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么,但是compilier的消息是函数试图返回一个数组(为什么会这样做?).如果我将函数的返回类型更改为void它将被编译.如果我传递另一种类型的参数(不是数组)它将被编译.数组有什么问题?
错误信息
../../untitled6/main.cpp: In instantiation of '<lambda(const auto:3&)> [with auto:3 = char [15]]':
../../untitled6/main.cpp:74:25: required from here
../../untitled6/main.cpp:68:84: error: no matching function for call to 'autofunc(const char [15])'
auto lambd = [](const auto& word){ autofunc(std::forward< decltype(word) > (word));};
^
../../untitled6/main.cpp:68:84: note: candidate is:
../../untitled6/main.cpp:60:17: …Run Code Online (Sandbox Code Playgroud)