operator overloaded in base class doesn't work for derived


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: operator overloaded in base class doesn't work for derived

  1. #1
    mrinal Guest

    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
    )

  2. #2
    Eric Gunnerson Guest

    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center