CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Pointer Initialization (https://www.cfd-online.com/Forums/openfoam-programming-development/146052-pointer-initialization.html)

SprayStef December 17, 2014 13:58

Pointer Initialization
 
Hi,

I am still new in OpenFOAM and I'm having issues initializing a pointer of the type autoPtr<scalar>&.

I declared a protected variable and a public function to access the value it is gonna point to in functions that belong to other classes

Code:

autoPtr<scalar>& BtTrans_;

inline autoPtr<scalar>& BtTrans();

BtTrans() is defined as follows:

Code:

template<class CloudType>
inline Foam::autoPtr<Foam::scalar>&
Foam::MyEvaporationAS<CloudType>::BtTrans()
{
    return BtTrans_;
}


Now in the constructor of my class I wanted to initialize BtTrans_ like so:

Code:

BtTrans_(NULL)
or
Code:

BtTrans_(0.0)
Dont work and I get the following error message:

error: invalid initialization of non-const reference of type `Foam::autoPtr<double>&’ from an rvalue of type ‘double’

Maybe one of you can help me with his/her thoughts on this issue?!

Thanks so much,
Stef

EDIT:

I've found the error. The declaration of BtTrans_ was incorrect. Should have been:

Code:

autoPtr<scalar> BtTrans_;

Now I have issues assigning the pointer to the variable I want it to point to.

How do I do that correctly?

Code:

template<class CloudType>
void Foam::MyEvaporationAS<CloudType>::calculate(...) const
{
  Bt= 5.0;
  BtTrans_ = &Bt;

}


The error I'm getting is the following:

error: no match for ‘operator=’ in ‘((const Foam::MyEvaporationAS<Foam::ReactingCloud<Foam::Th ermoCloud<Foam::KinematicCloud<Foam::Cloud<Foam::R eactingParcel<Foam::ThermoParcel<Foam::KinematicPa rcel<Foam::particle> > > > > > > >*)this)->Foam::MyEvaporationAS<Foam::ReactingCloud<Foam::T hermoCloud<Foam::KinematicCloud<Foam::Cloud<Foam:: ReactingParcel<Foam::ThermoParcel<Foam::KinematicP arcel<Foam::particle> > > > > > > >::BtTrans_ = & Bt’


All times are GMT -4. The time now is 07:13.