Afficher un message
Vieux 21/02/2008, 12h36   #3
Pallav singh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Class Template with Specialization code Giving Error

On Feb 21, 4:26 pm, Reetesh Mukul <reetesh.mu...@gmail.com> wrote:
> On Feb 21, 3:55 pm, Pallav singh <singh.pal...@gmail.com> wrote:> Hi
>
> > I am getting error in compiling this code .......Unable to find error
> > Kindly suggest me something.

>
> > Thanks
> > Pallav

>
> > ================================================== =================

>
> > #include<iostream.h>

>
> You should use <iostream> in place of iostream.h. For cout, you can
> use
> using std::cout;
>
>
>
> > template<typename T>
> > class B
> > {
> > public :

>
> > T DependentName;
> > int basefield;
> > typedef int X;

>
> > };

>
> > template<>
> > class B<char>
> > {

>
> > public :
> > enum E{basefield = 1};
> > int func()
> > { return basefield;}

>
> > };

>
> > template<typename T>
> > class D:B<T>
> > {
> > public :
> > int func()
> > { basefield = 12;

>
> Two errors in this step (when instantiation of D<char> is done):-
> 1)C++ does not permit implicit conversion from int type to enum type.
> That is you cannot write
> enum R{A,B};
> R x = 1;
>
> 2)basefield is an l-value, that is it is an integral constant, a
> lvalue. So you cannot assign
> any thing to it.
>
>
>
> > return basefield; }

>
> > };

>
> > void call(D<int> & obj_int){
> > cout<<"called function :: call(B<int> & obj_int) ::
> > "<<obj_int.func()<<endl;}

>
> > void call(D<char> & obj_char){
> > cout<<"called function :: call(B<char> & obj_char)::
> > "<<obj_char.func()<<endl;}

>
> > int main()
> > {

>
> > D<char> obj_char;
> > D<int> obj_int;

>
> > call(obj_char);
> > call(obj_int);

>
> > return 0;

>
> > }

>
> Regards,
> Reetesh Mukul


---------------------------------------------------------------------------------

Hi

as my knowledge with char ...it should look to Base class Specialized
function
where i am Not doing any assignment but access

while it should call generalized Base class for Other cases where i
did assigment

Thanks
Pallav
  Réponse avec citation
 
Page generated in 0,06103 seconds with 9 queries