// template_class.cc a template that needs two classes to instantiate // this should be in a file my_class.h template // user needs two class types for 'C1' and 'C2' class My_class { public: My_class(void){} My_class(C1 Adata1, C2 Adata2) { data1 = Adata1; /*data2 = Adata2;*/} // other functions using types C1 and C2 // using statements such as below put requirements on C1 and C2 int Get_mode(void) { return data1.i; } int Get_mode(C2 Adata3) { return Adata3.mode; } // ... protected: C1 data1; // C2 data2(7); // initialization not allowed here // ... }; // in users main program file // #include class A_class // users class that will be OK for template type 'C1' { public: A_class(void) { i = 3; } int i; }; class B_class // users class that will be OK for template type 'C2' { public: B_class(int Amode) { mode = Amode; stuff = 0.0; } int mode; private: double stuff; }; #include using namespace std; int main(void) { A_class AA; // we need an object of type A_class B_class B1(7); // we need an object of type B_class B_class B2(15); // another object My_class stuff; // 'stuff' is the instantiated template cout << "stuff.Get_mode(B1) " << stuff.Get_mode(B1) << endl; // now instantiate the template again to get the object 'things' My_class things(AA, B2); // using the constructor to // pass objects 'AA' and 'B2" cout << "things.Get_mode() " << things.Get_mode() << endl; return 0; } // output from execution is: // stuff.Get_mode(B1) 7 // things.Get_mode() 3