[Ipopt] Assign SmartPointer of child class to SmartPointer of base class

Uwe Nowak uwe.nowak at itwm.fraunhofer.de
Tue Feb 1 12:50:27 EST 2011


Thank you for the answer! With the hint of you and Mr. Laird the 
documentation became obvious... This solution works fine.
I was just not used to the intrinsic concept of SmartPtr (but to the 
boost version of shared pointer, where extracting the raw pointer is the 
last thing you want to do.)

Best Regards,

Am 01.02.2011 18:28, schrieb Stefan Vigerske:
> Hi,
> you can pass a raw MyNLP* pointer to the Application->OptimizeTNLP
> method. That will then automatically converted to a Ipopt::TNLP*, and
> that to an SmartPtr<Ipopt::TNLP*>.
> Since the number of references is stored in the TNLP object, there is no
> problem with this.
> To get the raw pointer, use GetRawPtr, e.g.,
>    Application->OptimizeTNLP(GetRawPtr(mynlp));
> Stefan
>> I have a class MyNLP that derives from Ipopt::TNLP.
>> Now I have a smart pointer Ipopt::SmartPtr<MyNLP>  to this instance.
>> However I have to pass a Ipopt::SmartPtr<Ipopt::TNLP>  to the
>> Application->OptimizeTNLP-Method.
>> Unfortunately the Smart Pointer is not automatically converted (as I was
>> used from the boost shared_ptr).
>> I know, that I can create a Ipopt::SmartPtr<Ipopt::TNLP>  holding a
>> reference to my MyNLP. But then I have to do a dynamic cast all the time
>> when I want to access MyNLP-Methods not in TNLP.
>> So what is the best way to have a reference to MyNLP and pass this in TNLP?
>> Thank You,
>> Uwe
>> _______________________________________________
>> Ipopt mailing list
>> Ipopt at list.coin-or.org
>> http://list.coin-or.org/mailman/listinfo/ipopt

Uwe Nowak
Fraunhofer-Institut für Techno- und Wirtschaftsmathematik
Abteilung Optimierung
Fraunhofer-Platz 1
D-67663 Kaiserslautern
Telefon:  +49(0)631/31600-4458
E-Mail:   uwe.nowak at itwm.fraunhofer.de
Internet: www.itwm.fraunhofer.de

More information about the Ipopt mailing list