小白求助 关于函数模板 前置声明的参数问题
void printI(T* arr, T2 len); //printI是函数模板 这里应该前置声明 的参数怎么填啊 void print(int* arr, int len)?void print(T* arr, T2 len)?template <typename T,typename T2>
void printI(T* arr, T2 len)
{
for (T2 i = 0; i < len; i++)
{
cout << arr << " ";
}
cout << endl;
} #include <iostream>
template <typename T, typename T2>
void printI(T *arr, T2 len);
int main() {
double data [] = {1.2, 2.3, 3.4};
printI(data, 3);
return 0;
}
template <typename T, typename T2>
void printI(T *arr, T2 len)
{
for (T2 i = 0; i < len; i++)
{
std::cout << arr << " ";
}
std::cout << std::endl;
}
页:
[1]