[英]C++ template class inheritance
#include <iostream>
using namespace std;
template <class T>
class C1
{
public:
int n;
C1(int a)
{
n=a;
}
T mat[50][50];
void readmat()
{
int i,j;
for(i=1; i<=n; i++)for(j=1; j<=n; j++)cin>>mat[i][j];
}
void showmat()
{
int i,j;
for(i=1; i<=n; i++)
{
cout<<endl;
for(j=1; j<=n; j++)cout<<mat[i][j]<<" ";
}
}
};
template <class T>
class C2: public C1<T>
{
C2(int a): C1(a) {};
};
每当我运行它时,都会出现错误:
在构造函数C2 :: C2(int)'中:
错误:类别“ C2”没有名为“ C1”的字段
如果有人可以向我解释我做错了什么,我将不胜感激。
您应该将template参数添加到基类
template <class T>
class C2: public C1<T>
{
C2(int a): C1<T>(a) {};
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.