1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
struct Data57_1 {
int a[2];
};
struct Data57_2 {
int a[2];
float b[3];
};
class C57 {
public:
virtual int show_data() =0;
};
template <int n, class T>
class D57 : public C57 {
public:
D57(int a0, int a1) {data.a[0] = a0; data.a[1] = a1;}
int show_data() {
cout << "a[0] = " << data.a[0] << endl;
return 0;
}
protected:
T data;
};
template <>
class D57<2,Data57_2> : public C57 {
public:
D57(int a0, int a1, float b0, float b1, float b2) {data.a[0] = a0; data.a[1] = a1; data.b[0] = b0; data.b[1] = b1; data.b[2] = b2;}
int show_data() {
cout << "a[0] = " << data.a[0] << endl;
cout << "b[0] = " << data.b[0] << endl;
return 0;
}
protected:
Data57_2 data;
};
//template <2,Data57_2> D57 : public C57;
//template D57<2,Data57_2> : public C57;
//template D57<2,Data57_2>;
int main(int argc, const char *argv[]) {
D57<1,Data57_1> d1(11, 12);
D57<2,Data57_2> d2(21, 22, 2.1, 2.2, 2.3);
C57* p1 = &d1;
C57* p2 = &d2;
p1->show_data();
p2->show_data();
return 0;
}
|