CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Pointer Initialization

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 17, 2014, 14:58
Default Pointer Initialization
  #1
New Member
 
Stefanie
Join Date: Oct 2014
Posts: 7
Rep Power: 12
SprayStef is on a distinguished road
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:article> > > > > > > >*)this)->Foam::MyEvaporationAS<Foam::ReactingCloud<Foam::T hermoCloud<Foam::KinematicCloud<Foam::Cloud<Foam:: ReactingParcel<Foam::ThermoParcel<Foam::KinematicP arcel<Foam:article> > > > > > > >::BtTrans_ = & Bt’

Last edited by SprayStef; December 18, 2014 at 16:02.
SprayStef is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CFD by anderson, chp 10.... supersonic flow over flat plate varunjain89 Main CFD Forum 18 May 11, 2018 08:31
FMG initialization query Mohsin FLUENT 6 November 2, 2016 03:02
Segmentation Fault caused by a pointer floquation OpenFOAM Programming & Development 1 October 17, 2014 12:43
CFX temperature initialization jp_ CFX 3 August 28, 2014 10:06
PtrDictionary: pointer with structure (order) of mesh maybee OpenFOAM Programming & Development 0 February 11, 2014 05:27


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