Now this may seem like a strange question, but I've come accross a compiler error that has just blown my mind and even though there is a fix, I'd like to know why it breaks.
So the pretense is I'm using an API called Corba, it's used for RPC in short. In my program I am having to create an object which derives from a Corba object.
class MyClass : public CorbaClass;
Simple stuff, now in one of the methods of MyClass
I am calling a function which requires a CorbaClass*
, so I simply pass in the this
pointer, note that the method is not a const method so surely this should work fine ?
However I get an error when compiling which states that the parameter I'm trying to pass is actually of type CorbaClass* const
. Now you can imagine my confusion, surely that is not possible, that would require this
to be an lvalue would it not ? So all of a sudden this has me questioning parts of my knowledge of C++ itself !
Now it turns out in the documentation of TAO (the specific implementation of Corba I'm using) that they actually have a snippet of code for this exact situation and I see they do something strange. Instead of directly passing this
, they call a method _this()
and pass the return from that through, so I did a bit of digging and found the method was declared in the Corba base class as:
CorbaClass* _this(void);
Now this seems completely insane to me, but maybe that's because I've never come accross it before, does anyone know why any of the weird stuff with this
is happening ?
I believe the compiler I'm using is GCC 4.5.1
Edit: Some example code
MyClass.h
class MyClass
: public POA_NotifyExt::ReconnectionCallback
{
public:
void Initialise();
private:
NotifyExt::ReconnectionRegistry_var m_ReconnectionRegistry;
}
MyClass.cpp
void Initialise()
{
m_ReconnectionRegistry->register_callback( this );
}
Generates error:
error: no matching function for call to ‘NotifyExt::ReconnectionRegistry::register_callback(MyClass* const)’
orbsvcs/NotifyExtC.h:491:63: note: candidate is: virtual NotifyExt::ReconnectionRegistry::ReconnectionID NotifyExt::ReconnectionRegistry::register_callback(NotifyExt::ReconnectionCallback*)