Overloading a buggy != operator

Discussion in 'C++' started by saadsj@gmail.com, Aug 11, 2006.

  1. Guest

    Hello,

    I'm in a situation where I'm using a library object that happens to
    have a bug in one of its operators. This bug was recently introduced
    into a new release of their library. Unfortunately, the option of
    reverting back to the previous, working version of the library is not
    possible. For discussion purposes, the bug is as follows:

    namespace System
    {
    inline bool operator !=( int inLeft, const Variant& inRight )
    {
    // While this is not the actual bug... it's pretty close.
    return false;
    }
    }

    As you can see the "!=" operator always returns false.

    So here it goes... I have no clue if this is possible with some C++
    magic so please forgive me if the idea sounds fantasy like or down
    right stupid. I would like to somehow overload the library's
    implementation of this != operator without having to modify their
    source. Then I could put my implementation in a "global" header file
    that every file in my project already includes.

    If anyone has ideas on how this can be done, your help would be greatly
    appreciated. Again, if this question is ridiculous please be gentle. :)


    Best regards,

    Scott
     
    , Aug 11, 2006
    #1
    1. Advertising

  2. wrote:
    > I'm in a situation where I'm using a library object that happens to
    > have a bug in one of its operators. This bug was recently introduced
    > into a new release of their library. Unfortunately, the option of
    > reverting back to the previous, working version of the library is not
    > possible. For discussion purposes, the bug is as follows:
    >
    > namespace System
    > {
    > inline bool operator !=( int inLeft, const Variant& inRight )
    > {
    > // While this is not the actual bug... it's pretty close.
    > return false;
    > }
    > }
    >
    > As you can see the "!=" operator always returns false.
    >
    > So here it goes... I have no clue if this is possible with some C++
    > magic so please forgive me if the idea sounds fantasy like or down
    > right stupid. I would like to somehow overload the library's
    > implementation of this != operator without having to modify their
    > source. Then I could put my implementation in a "global" header file
    > that every file in my project already includes.
    >
    > If anyone has ideas on how this can be done, your help would be
    > greatly appreciated. Again, if this question is ridiculous please be
    > gentle. :)


    I am not sure what the problem is. You just described the solution,
    implement your own and put it in your header that is included by every
    TU that needs it. So, have you already done that and there is some
    problem? What kind? If you haven't yet done what you thought about,
    why? And how can we help you with what you already know?

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Aug 11, 2006
    #2
    1. Advertising

  3. Guest

    Sorry Victor, I totally forgot to mention that part. I get an error
    that the "body has already been defined for the function". I figured
    that because of this error, overloading a function in a pre-existing
    namespace was not possible.

    Does the error I'm getting seem correct to you, given the situation?

    Scott


    Victor Bazarov wrote:
    > wrote:
    > > I'm in a situation where I'm using a library object that happens to
    > > have a bug in one of its operators. This bug was recently introduced
    > > into a new release of their library. Unfortunately, the option of
    > > reverting back to the previous, working version of the library is not
    > > possible. For discussion purposes, the bug is as follows:
    > >
    > > namespace System
    > > {
    > > inline bool operator !=( int inLeft, const Variant& inRight )
    > > {
    > > // While this is not the actual bug... it's pretty close.
    > > return false;
    > > }
    > > }
    > >
    > > As you can see the "!=" operator always returns false.
    > >
    > > So here it goes... I have no clue if this is possible with some C++
    > > magic so please forgive me if the idea sounds fantasy like or down
    > > right stupid. I would like to somehow overload the library's
    > > implementation of this != operator without having to modify their
    > > source. Then I could put my implementation in a "global" header file
    > > that every file in my project already includes.
    > >
    > > If anyone has ideas on how this can be done, your help would be
    > > greatly appreciated. Again, if this question is ridiculous please be
    > > gentle. :)

    >
    > I am not sure what the problem is. You just described the solution,
    > implement your own and put it in your header that is included by every
    > TU that needs it. So, have you already done that and there is some
    > problem? What kind? If you haven't yet done what you thought about,
    > why? And how can we help you with what you already know?
    >
    > V
    > --
    > Please remove capital 'A's when replying by e-mail
    > I do not respond to top-posted replies, please don't ask
     
    , Aug 11, 2006
    #3
  4. Guest

    wrote:
    > Hello,
    >
    > I'm in a situation where I'm using a library object that happens to
    > have a bug in one of its operators. This bug was recently introduced
    > into a new release of their library. For discussion purposes, the bug
    > is as follows:
    >
    > namespace System
    > {
    > inline bool operator !=( int inLeft, const Variant& inRight )
    > {
    > // While this is not the actual bug... it's pretty close.
    > return false;
    > }
    > }
    >
    > As you can see the "!=" operator always returns false.
    >
    > I would like to somehow overload the library's
    > implementation of this != operator without having to modify their
    > source. Then I could put my implementation in a "global" header file
    > that every file in my project already includes.


    Overloading means adding a function with the same "name" (in this
    case "operator !=") but other arguments. That won't help you here.

    What you need to do is subclass from System::Variant, and define that
    as BugFix::Variant. All functions except operator!= will forward
    directly;
    you can provide your own !=

    However, whatever you do won't fix the use of the original operator!=
    in the library itself. And since it's likely inlined, you can't fix it
    with
    linker tricks. Really, there's a reason people tell you to go back or
    forward to a proper version.

    Regards,
    Michiel Salters
     
    , Aug 14, 2006
    #4
  5. Guest

    wrote:
    > wrote:
    > > Hello,
    > >
    > > I'm in a situation where I'm using a library object that happens to
    > > have a bug in one of its operators. This bug was recently introduced
    > > into a new release of their library. For discussion purposes, the bug
    > > is as follows:
    > >
    > > namespace System
    > > {
    > > inline bool operator !=( int inLeft, const Variant& inRight )
    > > {
    > > // While this is not the actual bug... it's pretty close.
    > > return false;
    > > }
    > > }
    > >
    > > As you can see the "!=" operator always returns false.
    > >
    > > I would like to somehow overload the library's
    > > implementation of this != operator without having to modify their
    > > source. Then I could put my implementation in a "global" header file
    > > that every file in my project already includes.

    >
    > Overloading means adding a function with the same "name" (in this
    > case "operator !=") but other arguments. That won't help you here.
    >
    > What you need to do is subclass from System::Variant, and define that
    > as BugFix::Variant. All functions except operator!= will forward
    > directly;
    > you can provide your own !=
    >
    > However, whatever you do won't fix the use of the original operator!=
    > in the library itself. And since it's likely inlined, you can't fix it
    > with
    > linker tricks. Really, there's a reason people tell you to go back or
    > forward to a proper version.
    >
    > Regards,
    > Michiel Salters


    Michiel,

    Thank you for the reply. I like your proposed solution, and I think
    that works fine for the Variant::eek:perator != (this is where the Variant
    shows up on the left side of the comparison).

    However, what about when the Variant shows up on the right side of the
    comparison? The example I gave in the original posting is the !=
    operator for when an integer is on the left and the Variant is on the
    right. This function is still defined within the System namespace, but
    it is not part of the Variant object... it's kind of a standalone
    function.

    Again, your help is greatly appreciated.

    Best regards,

    Scott
     
    , Aug 14, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Smith
    Replies:
    2
    Views:
    423
    Ivan Vecerina
    Oct 6, 2004
  2. Replies:
    11
    Views:
    735
    James Kanze
    May 16, 2007
  3. hurcan solter
    Replies:
    3
    Views:
    733
    Cholo Lennon
    Aug 29, 2007
  4. Replies:
    11
    Views:
    562
  5. Replies:
    2
    Views:
    312
Loading...

Share This Page