Vas*_*rcu 2 c++ inheritance templates class
#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) {};
};
Run Code Online (Sandbox Code Playgroud)
每当我运行它时,我都会收到错误:
在构造函数C2 :: C2(int)'中:
错误:类'C2'没有名为'C1'的字段
如果有人能向我解释我做错了什么,我会非常感激.
您应该将模板参数添加到基类
template <class T>
class C2: public C1<T>
{
C2(int a): C1<T>(a) {};
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
104 次 |
| 最近记录: |