Idea: Lazy upcasting
Aarti_pl
aarti at interia.pl
Tue Mar 27 05:37:39 PDT 2007
Davidl napisał(a):
> class baseclass
> {
> }
> class inheritedclass:baseclass
> {
> int j(){}
> }
> let's see what upcast would happen:
>
> auto baseinst = new baseclass;
> inheritedclass inheritedinst= cast(inheritedclass)cast(void*) baseinst;
> inheritedinst.j(); <--- oops , AV here
This is example of downcast - casting from base class to inherited
class. This operation can always be dangerous.
But clue of my idea is to AVOID downcasting. There should be no casting
at all in case which I have described in my proposition.
>
> implicitly upcasting could cause tons of bugs
>
> and how do u know when u don't want implicit casting but it casts?
>
>
Proposition has also nothing to do with implicit downcasting. It has
more with upcasting, but in opposite way - implicit upcasting should be
disallowed in some cases :-)
If my proposition is not clear in some aspects, feel free to ask
questions. I am not a native speaker, so parts of this proposition could
be unclear...
Regards
Marcin Kuszczak
(aarti_pl)
More information about the Digitalmars-d
mailing list