[omniORB] My program crashes when I try to dereference an object
from a sequence
Martin Trappel
0xCDCDCDCD at gmx.at
Tue Oct 28 11:15:56 GMT 2008
Lane, Frank L wrote:
> Hi,
>
> My program is crashing and I don't understand why, will someone please
> tell me what I'm doing wrong?
> Visual Studio 2008, XP, OmniORB 4.1.3
>
>(...)
> Customer_impl * TheCustomer
> = new Customer_impl (CustomerName, CustomerAccount);
>
> cout << "New customer created, " << TheCustomer->Name()
> << ", " << TheCustomer->Account() << endl;
>
> CORBA::Long size = _Customers.length();
> _Customers.length(size+1);
> _Customers[size] = (Customer_ptr)TheCustomer;
>
Never, ever use c-style casts.
What you probably wanted to do was:
_Customers[size] = TheCustomer->_this();
> if (CORBA::is_nil(_Customers[0]))
> cout << "The newly created seq member is nil?" << endl;
> else {
> cout << "_Customers[0]: " << _Customers[0] << endl;
> cout << "TheCustomer: " << TheCustomer << endl;
> cout << "TheCustomer data, " << TheCustomer->Name()
> << ", " << TheCustomer->Account() << endl;
>
You are aware that the calls on TheCustomer are direct calls on the
implementation object, and won't involve any CORBA?
> !!!!! ----- Here is where it is crashing -----!!!!!!
> !!!!! ----- The instant I try to get data back out of the sequence it
> crashes ----- !!!!!!!
> Customer_var temp = (Customer_ptr)_Customers[0];
Never, ever use c-style casts.
You should use a _ptr type for the temp or duplicate() the sequence element!
> cout << "The sequence data, " << temp->Name()
> << ", " << (*temp).Account() << endl;
> //cout << "New customer created, " << _Customers[0]->Name() <<
> endl;
> }
>
>
> return Customer::_duplicate((Customer_ptr)TheCustomer);
>
Never, ever use c-style casts.
1) Look at the omniORB examples. example #1 will show you how to
correctly instantiate and the use an object.
2) After looking at the examples, get "Adavced CORBA programming with
C++" by Henning,Vinoski
br,
Martin
More information about the omniORB-list
mailing list