Why can't overload type cast to base type (object) 
Author Message
 Why can't overload type cast to base type (object)

Why can't overload type cast to base type object?????

public static operator object (Bla bla)
{
  return //some object

Quote:
}

Where is the power of C/C++?
No freedom at all!!!!

ImpC



Sat, 10 Jan 2004 20:00:49 GMT  
 Why can't overload type cast to base type (object)
You can't overload it because there is a built-in conversion from a type to
its base type.

To do otherwise would require a pretty big change to the CLR type system.


Quote:
> Why can't overload type cast to base type object?????

> public static operator object (Bla bla)
> {
>   return //some object
> }

> Where is the power of C/C++?
> No freedom at all!!!!

> ImpC



Sun, 11 Jan 2004 03:57:07 GMT  
 Why can't overload type cast to base type (object)
Type casts don't involve code.  They are simply changing the way you are
viewing the variable.  This is not a conversion.


Quote:
> You can't overload it because there is a built-in conversion from a type
to
> its base type.

> To do otherwise would require a pretty big change to the CLR type system.



> > Why can't overload type cast to base type object?????

> > public static operator object (Bla bla)
> > {
> >   return //some object
> > }

> > Where is the power of C/C++?
> > No freedom at all!!!!

> > ImpC



Sun, 11 Jan 2004 12:28:33 GMT  
 Why can't overload type cast to base type (object)
From the C# perspective, type casts are conversions; there's no difference
in terminology between what happens when you do:
int i = shortvariable;

and

Base b = derivedref;

They're both conversions. The first is an implicit numeric conversion
(section 6.1.2) and the second is an implicit reference conversion (6.1.4).


Quote:
> Type casts don't involve code.  They are simply changing the way you are
> viewing the variable.  This is not a conversion.



> > You can't overload it because there is a built-in conversion from a type
> to
> > its base type.

> > To do otherwise would require a pretty big change to the CLR type
system.



> > > Why can't overload type cast to base type object?????

> > > public static operator object (Bla bla)
> > > {
> > >   return //some object
> > > }

> > > Where is the power of C/C++?
> > > No freedom at all!!!!

> > > ImpC



Mon, 12 Jan 2004 01:44:22 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Type Casting between Base and Derived Type (Serialization of objects with Type members)

2. Operator overloading and type cast

3. array issue 'type cast warning'

4. Compiler error C2440: 'type cast'

5. error C2440: 'type cast' :

6. type casting to / from pointers to incomplete data types

7. type casting to / from pointers to incomplete data types

8. cast cstring type to integer type

9. Casting to/from STL types to MFC types

10. Why cast NULL to a type?

11. Why type cast??

12. C# Base Types vs. .NET Types

 

 
Powered by phpBB® Forum Software