Problem with references

Hello.

I am updating old version of program to a new version.

In old version, result of function internalField() was non-const reference, and in new program, result of that function is a const reference. When I compile program, I have errors due to this reason. For example,

1
2
3
4
5
    volScalarField& ParticleSum        = ParticleSumPtr_();
    volVectorField& ParticleUSum       = ParticleUSumPtr_();
    volVectorField& ParticleUsqSum     = ParticleUsqSumPtr_();

    scalarField& nPart = ParticleSum.internalField();


How can I overcome this problem? For example, nPart is variable, this shouldn't be a constant.

Full files are here

https://www.dropbox.com/s/32imv3eg2m03843/ParticleStatistics.zip?dl=0

Regards,
Darko

Last edited on
Hi,
Can you show us the complier error logs?

Also, don't hesitate to post your code directly on the forum. You probably would get replies much faster if you did as what I say.
Log is here

https://www.dropbox.com/s/18ox5nz6afbz58i/log?dl=0

It has a lot of errors, but I go slowly. I want to solve first group of errors, with binning.

What section you recommend to post this question? I can close this question here and open there ...

Thank you.

P. S. If you respond me, don't expect answer tonight. I am at my workplace, I am going home now. I will continue tomorrow.
Last edited on
Sadly, many people will really not open the links. They don't want to wait or do some extra steps to be able to see yours. And remember, this is not a homework site.

You need to post your code and your stuff here. This is a forum. Once you make your thread interactive enough, people will start to interact. And there's also a Job section if you want someone to do it entirely & privately for you.

:D
Do you want to modify the scalarField? If not then you should be fine with a const reference.

 
const scalarField& nPart = ParticleSum.internalField();


If you do want to modify the scalarField object then you have to change internalField() to return a non-const reference. Another possibility is to add additional functions the volScalarField class to set/update the object.
Unfortunately, I need to modify scalarField.

I can't change internalField return, because many other programs depend on that function.

I will try to add one similar function with non-const reference.

I will try that and report results.

Thank you!


Note that you can overload the internalField() function so that you have both a const and a non-const version.

1
2
const scalarField& internalField() const;
scalarField& internalField();

That way you can call internalField() in both const and non-const situations. The non-const version will be preferred but if it's not possible (because the volVectorField is const) it will instead call the const version.
Last edited on
I have overloaded function like you said, and I don't have this error anymore. I am continuing to fix other errors.

Thank you once again.

Regards,
Darko

Topic archived. No new replies allowed.