CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Accessing a private member from a different namespace and class to a template class

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 5, 2020, 14:37
Default 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
pankajadgjmp is on a distinguished road
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_;
}
pankajadgjmp is offline   Reply With Quote

Old   April 6, 2020, 11:36
Default
  #2
Senior Member
 
Tom-Robin Teschner
Join Date: Dec 2011
Location: Cranfield, UK
Posts: 211
Rep Power: 16
t.teschner is on a distinguished road
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.
t.teschner is offline   Reply With Quote

Reply

Tags
c++, cfd, error, openfoam, programing


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
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


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