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 4 1349 sa****@gmail.com 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
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:
sa****@gmail.com 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
sa****@gmail.com 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 Mi*************@tomtom.com wrote:
sa****@gmail.com 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::operator != (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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: |
last post by:
Hi all,
I've been using C++ for quite a while now and I've come to the point where I need to overload new
and delete inorder to track memory and probably some profiling stuff too. I know that...
|
by: gorda |
last post by:
Hello,
I am playing around with operator overloading and inheritence,
specifically overloading the + operator in the base class and its
derived class.
The structure is simple: the base class...
|
by: zeus |
last post by:
I know function overloading is not supported in C.
I have a few questions about this:
1. Why? is it from technical reasons? if so, which?
2. why wasn't it introduced to the ANSI?
3. Is there any...
|
by: luca regini |
last post by:
I have this code
class M
{
.....
T operator()( size_t x, size_t y ) const
{ ... Operator overloading A ....}
T& operator()( size_t x, size_t y )
|
by: brzozo2 |
last post by:
Hello, this program might look abit long, but it's pretty simple and
easy to follow. What it does is read from a file, outputs the contents
to screen, and then writes them to a different file. It...
|
by: y-man |
last post by:
Hi,
I am trying to get an overloaded operator to work inside the class it
works on. The situation is something like this:
main.cc:
#include "object.hh"
#include "somefile.hh"
object obj,...
|
by: jakester |
last post by:
I am using Visual C++ 2007 to build the code below. I keep getting
linkage error. Could someone please tell me what I am doing wrong? The
code works until I start using namespace for my objects.
...
|
by: Colonel |
last post by:
It seems that the problems have something to do with the overloading of
istream operator ">>", but I just can't find the exact problem.
// the declaration
friend std::istream &...
|
by: Wayne Shu |
last post by:
Hi everyone, I am reading B.S. 's TC++PL (special edition).
When I read chapter 11 Operator Overloading, I have two questions.
1. In subsection 11.2.2 paragraph 1, B.S. wrote "In particular,...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |