-
operator overloaded in base class doesn't work for derived
Hi ,
i made a small program in which i overloaded an operator in base class
and few other operators in derived class , now while using all of them from
main using derive class object it's giving problem as it says that ,
can't implicitly convert base class to derive one ,
or a particular operator can't be applied to both types ( base & derived
)
-
Re: operator overloaded in base class doesn't work for derived
Derived types tend to be enough different from base types that they can't be
used interchangably, and the overloaded operators wouldn't work well.
If the types really are the same type (but the derived one just adds more
methods, for example), you can use implicit user-defined conversions to get
the base ones called, but that's no a good idea in general.
The safest thing is to write the operators in the derived class and forward
them to the base class version.
--
Visit the C# product team at http://www.gotdotnet.com/team/csharp
This posting is provided "AS IS" with no warranties, and confers no rights.
"mrinal" <mrinal@iiitb.ac.in> wrote in message news:3d08cb10$1@10.1.10.29...
>
> Hi ,
> i made a small program in which i overloaded an operator in base class
> and few other operators in derived class , now while using all of them
from
> main using derive class object it's giving problem as it says that ,
>
> can't implicitly convert base class to derive one ,
>
> or a particular operator can't be applied to both types ( base & derived
> )
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks