|
[Sponsors] |
Accessing a private member from a different namespace and class to a template class |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
April 5, 2020, 14:37 |
Accessing a private member from a different namespace and class to a template class
|
#1 |
New Member
pankaj sharma
Join Date: Feb 2016
Posts: 9
Rep Power: 10 |
I am trying to access a private member from a class with radiation namespace, to a template class in Foam namespace. I tried replicating a similar (own c++ code ) and simple test code with multiple namespace and classes and was successful. But the moment I want to use that same method in OpenFOAM I get errors.
did anyone came across a similar problem or have a solution please help. The error says "multiple definition of `Foam::radiation::accessd_(Foam::radiation:Eradi ativeIntensityRay)' ".. Although the error might not make sense without the program but it is something like this friend int accessd_(DEradiativeIntensityRay obj); }; // End of class //DEradiativeIntensityRay user; //object to access d_ int accessd_(DEradiativeIntensityRay obj) // the line of error { int private_{0}; private_ = obj.test; Info<<" The value of private is "<<private_ <<endl; return private_; } |
|
April 6, 2020, 11:36 |
|
#2 |
Senior Member
Tom-Robin Teschner
Join Date: Dec 2011
Location: Cranfield, UK
Posts: 211
Rep Power: 17 |
well, going by your incomplete code snippets it is virtually impossible to diagnose the problem. could you share the code which is working so that it is clear what you are trying to achieve? sometimes the approach may not be the best and there is a better solution available, maybe that is the case here?!
When you want to access private members, you would almost always want to do that through a getter method. I am not sure what is holding you back in this case to use a function of the form int DEradiativeIntensityRay::get() { return test; } (maybe you don't want to recompile the OpenFOAM codebase?!), so that information would help as well. "Friends" don't really work well in an object orientated approach, much like a goto statement (at least in my opinion), but there are always legitimate reasons to do that, so a code example would help here. |
|
Tags |
c++, cfd, error, openfoam, programing |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
BasicTurbulenceModel class declaration in OpenFOAM 6 | rod_petrone | OpenFOAM Programming & Development | 3 | April 15, 2019 09:27 |
Adding new member function to GidaspowErgunWenYu.C of dragModel | kiang | OpenFOAM Programming & Development | 0 | June 21, 2017 06:23 |
Calculation of rotational equation of motion using DPMFoam | ansubru | OpenFOAM Programming & Development | 4 | November 1, 2014 12:57 |
Doxygen documentation | Tanay | OpenFOAM Installation | 9 | September 23, 2011 12:40 |
member function [value()] of dimensioned<Type> class | sblee1977 | OpenFOAM Programming & Development | 2 | November 9, 2010 04:52 |