本文介绍了模板功能导致错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

获取错误:

Getting the error:

error C2027: use of undefined type 'T'



包括具有以下定义的模板标题:


While including a template header with the following definition:

//** Maximum value in a vector **//
template <typename T> 
T max(vector<T>& input,int* index_of_maximum = NULL)
{
	vector<T>::iterator i = input.begin();
	T maximum = *i;
	int index = 0;

	for(i++; i!=input.end(); i++){
		if(*i>maximum)
			maximum = *i;
		index++;
	}

	if(index_of_maximum)
		*index_of_maximum = index-1;

	return maximum;
}





不确定为什么编译器会调用该错误。我有一个项目工作正常,另一个项目导致该错误。必须是导致此奇怪错误的一些设置。有什么建议吗?



Not sure why the compiler is calling that an error. I have one project where that works fine and another project where it results in that error. Must be some setting that results in this odd error. Any suggestions?

推荐答案


这篇关于模板功能导致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 14:06