#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
template <typename T>
typename T::ElementT Get(T const* a, int k) //这个ElementT是什么东东????
{
return a[k];
}
void func(char* p)
{
char c1 = Get<char>(p, 0);
//error C2770: invalid explicit template argument(s) for 'T::value Get(const T *,int)'
//Get<char*>(p, 0);
//error C2770: invalid explicit template argument(s) for 'T::value Get(const T *,int)'
char c2 = Get(p, 2);
//error C2893: Failed to specialize function template 'T::value Get(const T *,int)'
cout<<"c1 = "<<c1<<endl;
cout<<"c2 = "<<c2<<endl;
}
int main()
{
char cc[] = "abcd";
func(cc);
getch();
}
c++ 模板的一个例子,实参演绎的时候,有个地方没看明白
最新推荐文章于 2024-09-25 10:36:42 发布