c++ 函数模板 部分排序规则

C++语言 码拜 9年前 (2015-11-16) 1186次浏览
#include <iostream>
using namespace std;
//template A
template <class T>
void ShowArray(T arr[],int n);
//template B
template <class T>
void ShowArray(T* arr[],int n);
struct debts
{
char name[50];
double amount;
};
int main()
{
int things[6]={13,31,103,301,310,130};
struct debts mr_E[3]=
{
{“Ima Wolfe”,2400.0},
{“Ura Foxe”,1300.0},
{“Iby Stout”,1800.0}
};
double* pd[3];
//set pointers to the amount members of the structures in the arr_mr_E
for(int i=0;i<3;i++)
pd[i]=&mr_E[i].amount;
cout<<“Listing Mr.E””s counts of things:\n”;
//things is an array of int
ShowArray(things,6);
//pd is an array of pointers to double
ShowArray(pd,3);//uses template B
return 0;
}
template <class T>
void ShowArray(T arr[],int n)
{
cout<<“template A.\n”;
for(int i=0;i<n;i++)
cout<<arr[i]<<“.\n”;
}
template <class T>
void ShowArray(T* arr[],int n)
{
cout<<“template B.\n”;
for(int i=0;i<n;i++)
cout<<*arr[i]<<“.\n”;
}
C:\Users\Administrator\Desktop\c++实战\c++program\8函数探幽_函数模板_部分排序规则\main.cpp(35) : error C2667: “”ShowArray”” : none of 2 overload have a best conversion
C:\Users\Administrator\Desktop\c++实战\c++program\8函数探幽_函数模板_部分排序规则\main.cpp(35) : error C2668: “”ShowArray”” : ambiguous call to overloaded function
解决方案:5分
clang 编译没问题。
解决方案:5分
换编译器好了
解决方案:5分
你用什么IDE,本人在VS2012中可以通过
解决方案:6分
太老了,对泛型、STL、及新标准都支持的不太好,LZ换VS吧
解决方案:6分
切记 VC6中不要用模板,一般模板用法VS2003以上,高级一些的模板得VS2008以上。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明c++ 函数模板 部分排序规则
喜欢 (0)
[1034331897@qq.com]
分享 (0)