P
Pallav singh
I am Facing Problem while creating object of Diamond Ring problem
solving using Template
Kindly let me known where i am committing ERROR
Thanks
Pallav
#include<iostream.h>
#include<string.h>
template<typename T>
class A
{
private :
T a;
public :
A(T a1):a(a1){}
A(const A<T>& a){}
~A(){}
void Get_Value()const
{cout<<"Value of a :: "<< a <<endl<<"\n";}
};
template<typename T ,typename U>
class B :virtual public A<T>
{
private :
U b;
U c;
public :
B(T a1,U b1):A<T>(a1),b(b1),c(b1){}
B(const B<T,U>& b){}
~B(){}
void Show_Value_B()const
{ cout<<"Value of B___ b is :: "<<b <<endl<<"\n";
cout<<"Value of B___ c is :: "<<c <<endl<<"\n";
}
};
template<typename T ,typename V>
class C :virtual public A<T>
{
private :
V b;
V c;
public :
C(T a1,V b1):A<T>(a1),b(b1),c(b1){}
C(const C<T,V>& c){}
~C(){}
void Show_Value_C()const
{ cout<<"Value of C___ b is :: "<<b <<endl<<"\n";
cout<<"Value of C___ c is :: "<<c <<endl<<"\n";
}
};
template<typename T,typename U ,typename V>
class D :virtual public B<T,U>, virtual public C<T,V>
{
public :
D(T a,U b,V c):B<T,U>(a,b),C<T,V>(a,c){}
D(const D<T,U,V> &d){}
~D(){};
};
int main(int argc , char *argv[])
{
D<int,char,float> b(12,'V',17.8);
b.Get_Value();
b.Show_Value_C();
b.Show_Value_B();
return 0;
}
solving using Template
Kindly let me known where i am committing ERROR
Thanks
Pallav
#include<iostream.h>
#include<string.h>
template<typename T>
class A
{
private :
T a;
public :
A(T a1):a(a1){}
A(const A<T>& a){}
~A(){}
void Get_Value()const
{cout<<"Value of a :: "<< a <<endl<<"\n";}
};
template<typename T ,typename U>
class B :virtual public A<T>
{
private :
U b;
U c;
public :
B(T a1,U b1):A<T>(a1),b(b1),c(b1){}
B(const B<T,U>& b){}
~B(){}
void Show_Value_B()const
{ cout<<"Value of B___ b is :: "<<b <<endl<<"\n";
cout<<"Value of B___ c is :: "<<c <<endl<<"\n";
}
};
template<typename T ,typename V>
class C :virtual public A<T>
{
private :
V b;
V c;
public :
C(T a1,V b1):A<T>(a1),b(b1),c(b1){}
C(const C<T,V>& c){}
~C(){}
void Show_Value_C()const
{ cout<<"Value of C___ b is :: "<<b <<endl<<"\n";
cout<<"Value of C___ c is :: "<<c <<endl<<"\n";
}
};
template<typename T,typename U ,typename V>
class D :virtual public B<T,U>, virtual public C<T,V>
{
public :
D(T a,U b,V c):B<T,U>(a,b),C<T,V>(a,c){}
D(const D<T,U,V> &d){}
~D(){};
};
int main(int argc , char *argv[])
{
D<int,char,float> b(12,'V',17.8);
b.Get_Value();
b.Show_Value_C();
b.Show_Value_B();
return 0;
}