You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
452 B
C++
24 lines
452 B
C++
An Example with Two Generic Data Types
|
|
#include <iostream>
|
|
using namespace std;
|
|
|
|
template <class Type1, class Type2> class myclass
|
|
{
|
|
Type1 i;
|
|
Type2 j;
|
|
public:
|
|
myclass(Type1 a, Type2 b) { i = a; j = b; }
|
|
void show() { cout << i << ' ' << j << '\n'; }
|
|
};
|
|
|
|
int main()
|
|
{
|
|
myclass<int, double> ob1(10, 0.23);
|
|
myclass<char, char *> ob2('X', "Templates add power.");
|
|
|
|
ob1.show();
|
|
ob2.show();
|
|
|
|
return 0;
|
|
}
|