关于语法
  • 板块学术版
  • 楼主Eason_AC
  • 当前回复10
  • 已保存回复10
  • 发布时间2021/8/12 09:42
  • 上次更新2023/11/4 10:57:55
查看原帖
关于语法
112917
Eason_AC楼主2021/8/12 09:42

RT,我写了一个这样的函数:

template<typename T, template... args>
	inline void print_space_mul(T x, args ...Args) {
		print_space(x);//之前已经有的函数,大概就是用来实现在输出 x 后面在输出一个空格
		print_space_mul(Args...);
	}

大概意思已经很明了了吧,就是想实现多个数一起输出,中间以空格间隔。

然后我这么调用这个函数的:

int x = 2, y = 4, z = 6;
		print_space_mul(x, y, z, mygcd(x, y, z), mylcm(x, y, z), mymax(x, y, z), mymin(x, y, z), myabs(x), myabs(y), myabs(z));//以上函数均已定义,并且疑似应该很明白

然后它出现了编译错误:

C:\Users\Mac\Desktop\C++\test019.cpp	In instantiation of 'void FullPre::print_space_mul(T, args ...) [with T = int; args = {}]':
70	84	C:\Users\Mac\Desktop\C++\test019.cpp	recursively required from 'void FullPre::print_space_mul(T, args ...) [with T = int; args = {int, int, int, int, int, int, int, int}]'
70	84	C:\Users\Mac\Desktop\C++\test019.cpp	required from 'void FullPre::print_space_mul(T, args ...) [with T = int; args = {int, int, int, int, int, int, int, int, int}]'
105	120	C:\Users\Mac\Desktop\C++\test019.cpp	required from here
70	84	C:\Users\Mac\Desktop\C++\test019.cpp	[Error] no matching function for call to 'print_space_mul()'
70	84	C:\Users\Mac\Desktop\C++\test019.cpp	[Note] candidate is:
70	9	C:\Users\Mac\Desktop\C++\test019.cpp	[Note] template<class T, class ... args> void FullPre::print_space_mul(T, args ...)
70	9	C:\Users\Mac\Desktop\C++\test019.cpp	[Note] template argument deduction/substitution failed:
70	84	C:\Users\Mac\Desktop\C++\test019.cpp	[Note] candidate expects 2 arguments, 0 provided

求问应该怎么解决 /kel

2021/8/12 09:42
加载中...