【发布时间】:2014-03-16 08:45:42
【问题描述】:
我正在尝试制作一个模板函数并通过引用将两个变量传递给它,每件事听起来都不错,但它从未编译过,错误消息是:-
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
我尝试了一小部分代码,它给了我同样的错误,请帮忙吗??
这是一部分代码,其他的代码都是这样的:
int size , found = -1 ;
template<class type> Read_Data( type &key , type &arr)
{
cout << " please enter the size of your set \n " ;
cin >> size ;
arr = new type[size];
cout << " please enter the elements of your set : \n " ;
for (int i = 0 ; i <size ; i ++ )
{
cout << " enter element number " << i << ": " ;
cin >> arr[i] ;
}
cout << " please enter the key elemente you want to search for : \n " ;
cin >> key ;
}
void main(void)
{
int key , arr ;
Read_Data (key, arr);
/*after these function there is two other functions one to search for key
in array "arr" and other to print the key on the screen */
}
【问题讨论】:
-
Read_Data没有返回类型,void main(void)是非标准的。 -
那么是什么让您认为它与模板有关?
标签: c++ templates pass-by-reference