#include <iostream>
#include <string>
#include <vector>
using namespace std;
// D. Create a C++ class template named Pair that represents a pair of values.
template <typename T>
class Pair {
private:
T A1;
T A2;
public:
Pair(T val1,T val2) {
A1 = val1; // initialize first ehe private variable then the Public variable
A2 = val2;
}
// display
void display() {
cout << "value A: " << A1 << " \nvalue B: " << A2 << endl;
}
};
int main() {
int x, y;
cout << "enter first value : ";
cin >> x;
cout << "enter second value : ";
cin >> y;
Pair<int> class1(x, y);
class1.display();
return 0;
}
No comments:
Post a Comment