| Title: | ObjectBroker Development - BEA Systems' CORBA |
| Notice: | See note 2 for kit locations; note 4 for training |
| Moderator: | RECV::GUMBEL d |
| Created: | Thu Dec 27 1990 |
| Last Modified: | Fri Jun 06 1997 |
| Last Successful Update: | Fri Jun 06 1997 |
| Number of topics: | 2482 |
| Total number of notes: | 13057 |
What are the generated impl constructors with the 'Instance'
arguments for?
Suppose I have an implementation MyImpl. I derive MyClass
from it:
class MyClass : MyImpl
ObjectBroker documentation recommends me to define
a constructor like this:
MyClass ( ) : MyImpl((void *)this) {};
Presumably this is to call the parent constructor with
the instance ('this') of the child. But this doesn't seem
to make sense because the constructor of the parent will in
ANY CASE have 'this' the same as the child. Instances of
MyClass ARE instances of MyImpl.
So if we look at the generated code (in the C++ imh file)
we find two constructors one with a "void * instance" one
without. The difference between these in the body of the
code is that we call Add with 'this' or 'Instance':
OBB_CXXAPI MyImpl() {
...
_OBB__instance_list->Add((void *)this, tmp_ev);
_OBB__instance_count++;
};
OBB_CXXAPI MyImpl( void * Instance) {
...
_OBB__instance_list->Add(Instance, tmp_ev);
_OBB__instance_count++;
};
But this is NO difference if 'Instance' is the 'this' of
the child. Because the 'this' of the parent *is* the
'this' of the child.
Anyway. If you write a server using associated objects and
simply derive MyClass from MyImpl - everything works fine.
The parent constructor is called, it uses 'this' and the
dispatcher dispatches methods in the correct instance.
That bizarre syntax is confusing to customers and students
(not to mention teachers!). And you seem to generate twice
as many constructors as necessary.
Help me to understand this.
John D.
| T.R | Title | User | Personal Name | Date | Lines |
|---|---|---|---|---|---|
| 2434.1 | It is a workaround | RECV::VLATAS | WARNING: Do not swallow the battery door | Mon Feb 17 1997 07:20 | 29 |
>> MyClass ( ) : MyImpl((void *)this) {};
Actually, the old documentation was not quite correct (the V2.7 doc
supplement should have the correct syntax). You really need to do
the following:
MyClass ( ) : MyImpl((void *)(MyImpl *)this) {};
>> But this is NO difference if 'Instance' is the 'this' of
>> the child. Because the 'this' of the parent *is* the
>> 'this' of the child.
When we originally did the bindings we did try to do it as you
mentioned, but this didn't work on all of the platforms and we
had to add in the separate constructors. If memory serves, this
problem only showed up on one/two platforms when "virtual" inheritance
was used. The problem was that the offsets were not correctly
calculated and you ended up with an invalid instance pointer, causing
crashes/unpredictable behaviour when the generated callback routines
tried to use the instance pointer (ie: dispatcher, notifiers, etc).
I agree it is not obvious, but it was the only way we found that we
could get it to work with some of our supported compilers. It is
something that we want to get rid of, if possible, with the new
bindings for IIOP.
Tony
| |||||
| 2434.2 | LEMAN::DONALDSON | Froggisattva! Froggisattva! | Mon Feb 17 1997 09:20 | 9 | |
Re: <<< Note 2434.1 by Tony Thanks for the info. I'm glad really. My C++ knowledge is not Master class yet and I've been puzzling over it for a while now. It's also difficult when a student (who knows not much about OBB but lots about C++ asks what it's for!). John D. | |||||