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

attempted to assign to a const reference to constant object of type

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   June 15, 2015, 13:08
Default attempted to assign to a const reference to constant object of type
  #1
New Member
 
Przemek
Join Date: Jun 2011
Posts: 27
Rep Power: 6
gaza is on a distinguished road
Hi Foamers,
I'm stuck and I need your help wuth error as in the title of this post.
My piece of code is

volScalarField A( T );
volScalarField B( T );
return Pair<tmp<volScalarField> >
(
A,
B
);

T is also volScalarField defined in the createFields.H

Can you tell me why "attempted to assign to a const reference to constant object of type" error arise? I find out that the error arises in
the constructor of Pair, but I don't understand why? Here is the code from Pair.H

//- Construct from components 66 inline Pair(const Type& f, const Type& s)
67 {
68 first() = f;
69 second() = s;
70 }

//- Return first 88 inline const Type& first() const
89 {
90 return this->operator[](0);
91 }
92
93 //- Return first
94 inline Type& first()
95 {
96 return this->operator[](0);
97 }
98
99 //- Return second
100 inline const Type& second() const
101 {
102 return this->operator[](1);
103 }
104
105 //- Return second
106 inline Type& second()
107 {
108 return this->operator[](1);
109 }

and operator[]() from FixedList.H

242 inline T& Foam::FixedList<T, Size>:perator[](const label i) 243 {
244 # ifdef FULLDEBUG
245 checkIndex(i);
246 # endif
247 return v_[i];
248 }
249
250
251 // const element access
252 template<class T, unsigned Size>
253 inline const T& Foam::FixedList<T, Size>:perator[](const label i) const
254 {
255 # ifdef FULLDEBUG
256 checkIndex(i);
257 # endif
258 return v_[i];
259 }

Any help is really appreciated
__________________
best regards
pblasiak
gaza is offline   Reply With Quote

Old   June 16, 2015, 04:41
Default
  #2
New Member
 
Przemek
Join Date: Jun 2011
Posts: 27
Rep Power: 6
gaza is on a distinguished road
Can anybody help me?
__________________
best regards
pblasiak
gaza is offline   Reply With Quote

Old   June 16, 2015, 10:51
Default
  #3
New Member
 
Przemek
Join Date: Jun 2011
Posts: 27
Rep Power: 6
gaza is on a distinguished road
Hi all,
I solved my problem by implementation:
volScalarField A( T );
volScalarField B( T );
return Pair<tmp<volScalarField> >
(
A*scalar(1),
B*scalar(1)
);

I do not know why now it works?
This solution is not good. If anybody know how to fix it please share your knowledge.
I don't think so it is a bug in tmp class. Rather I do something wrong. But why can't I
return Pair of volScalarField?? It is strange.
__________________
best regards
pblasiak
gaza is offline   Reply With Quote

Old   June 17, 2015, 02:53
Default
  #4
New Member
 
Przemek
Join Date: Jun 2011
Posts: 27
Rep Power: 6
gaza is on a distinguished road
This is strange for me that if I want return

Pair<tmp<volScalarField> >(A,B);

A and B have to be expressions. For example


Pair<tmp<volScalarField> >(A*scalar(1),B*scalar(1));

works and Pair<tmp<volScalarField> >(A,B); does not.

Does anybody know why it is?
__________________
best regards
pblasiak
gaza is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Incompatible dimensions for operation ruben23 OpenFOAM Running, Solving & CFD 2 June 12, 2015 04:14
interFoam/kOmegaSST tank filling with printStackError/Mules simpomann OpenFOAM Running, Solving & CFD 3 February 17, 2014 18:06
compile error in dynamicMesh and thermophysicalModels libraries NickG OpenFOAM Installation 2 August 30, 2013 07:42
Air Conditioned room groovyBC Sebaj OpenFOAM 7 October 31, 2012 15:16
problem in making a new solver!!! adambarfi OpenFOAM Running, Solving & CFD 18 September 29, 2012 11:56


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