#include #include #include using namespace std; template class A { T a; U b; public: A(T a_val, char b_val = '$'){ this->a = a_val; this->b = b_val; } void print(){ cout< a1(5,10); A a2(5); A a3(10.0); a1.print(); a2.print(); a3.print(); return 0; } Give output for this code.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
template<class T, class U = char>
class A
{
T a;
U b;
public:
A(T a_val, char b_val = '$'){
this->a = a_val;
this->b = b_val;
}
void print(){
cout<<a<<' '<<b<<endl;
}
};
int main(int argc, char const *argv[])
{
A <int, int> a1(5,10);
A <int> a2(5);
A <float> a3(10.0);
a1.print();
a2.print();
a3.print();
return 0;
}
Give output for this code.

Step by step
Solved in 3 steps with 2 images









