[英]How to separate declaration and definition for template function with trailing return type?
I stumbled upon the same problem as in this question: Can't Separate Function Into Declaration and Definition with Trailing Return & Template , but there are no answers.我偶然发现了与这个问题相同的问题: Can'tseparate Function Into Declaration and Definition with Trailing Return & Template ,但没有答案。
Basically, I want to write the following:基本上,我想写以下内容:
namespace ALGLIB_wrappers
{
class Linear_least_squares
{
public:
template<typename Table, typename... Basis_function>
auto fit(const Table&, Basis_function... funcs) -> std::array<double, sizeof...(funcs)>;
};
}
template<typename Table, typename... Basis_function>
auto ALGLIB_wrappers::Linear_least_squares::fit(const Table& potential, Basis_function... funcs) -> std::array<double, sizeof...(funcs)>
{
// code
}
With g++-9 or g++10 I get the following error:使用 g++-9 或 g++10 我收到以下错误:
ALGLIB_wrappers.h:151:6: error: no declaration matches ‘std::array<double, sizeof... (funcs)> ALGLIB_wrappers::Linear_least_squares::fit(const Table&, Basis_function ...)’
151 | auto ALGLIB_wrappers::Linear_least_squares::fit(const Table& potential, Basis_function... funcs) -> std::array<double, sizeof...(funcs)>
| ^~~~~~~~~~~~~~~
ALGLIB_wrappers.h:15:8: note: candidate is: ‘template<class Table, class ... Basis_function> std::array<double, sizeof... (funcs)> ALGLIB_wrappers::Linear_least_squares::fit(const Table&, Basis_function ...)’
15 | auto fit(const Table&, Basis_function... funcs) -> std::array<double, sizeof...(funcs)>;
| ^~~
ALGLIB_wrappers.h:8:8: note: ‘class ALGLIB_wrappers::Linear_least_squares’ defined here
8 | class Linear_least_squares
| ^~~~~~~~~~~~~~~~~~~~
I don't get what I'm doing wrong.我不明白我做错了什么。
Is there any way to do that?有没有办法做到这一点?
Replacing sizeof...(funcs)
with sizeof...(Basis_function)
seems to work with g++, but I cannot explain why...用 sizeof...(Basis_function) 替换
sizeof...(funcs)
sizeof...(Basis_function)
似乎适用于 g++,但我无法解释为什么...
(note that your code works with clang++) (请注意,您的代码适用于 clang++)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.