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) {}; };
whenever run it, error:
in constructor c2::c2(int)':
error: class 'c2' not have field named 'c1'
if explain me did wrong, appreciate it.
you should add template parameter base class
template <class t> class c2: public c1<t> { c2(int a): c1<t>(a) {}; };
Comments
Post a Comment