我想用c ++编写一个日志文件.我正在处理某些事情,因此我需要维护我处理的事物的属性的日志,以便我可以恢复到这个日志文件,以查看我特别感兴趣的任何属性..有人可以帮助我实现这个?
这个例子使用了一个通用的可变参数模板和函数。我想打印出传递给的参数f:
#include <iostream>
template <typename T>
void print(T t)
{
std::cout << t << std::endl;
}
template <typename...T>
void f(T &&...args)
{
print(args...);
f(args...);
}
int main()
{
f(2, 1, 4, 3, 5);
}
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
Compilation finished with errors:<br>
source.cpp: In instantiation of '`void f(T ...)` [with `T = {int, int, int, int, int}`]':<br>
source.cpp:16:20: required from here <br>
source.cpp:10:4: error: no matching function for call to '`print(int&, int&, int&, int&, int&)`'<br>
source.cpp:10:4: note: candidate is:<br>
source.cpp:4:6: note: …Run Code Online (Sandbox Code Playgroud) c++ templates generic-programming function-templates variadic-templates