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

Stefan Vigerske stefan at math.hu-berlin.de
Tue Feb 1 12:28:11 EST 2011


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
> 


-- 
Stefan Vigerske
Humboldt University Berlin, Numerical Mathematics
http://www.math.hu-berlin.de/~stefan



More information about the Ipopt mailing list