CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   member function [value()] of dimensioned<Type> class (http://www.cfd-online.com/Forums/openfoam-programming-development/81819-member-function-value-dimensioned-type-class.html)

sblee1977 November 8, 2010 02:02

member function [value()] of dimensioned<Type> class
 
I tried to understand the code of OpenFOAM, specifically simplefoam, but I met a small obstacle in the usage of value() function which is a memeber function of dimensioned<Type> class.

In the constructor of Time class, setControls() is executed and setControls calls the function of setTime(starTime_, 0). In the function of setTime, value()=newTime is not clear.

Let me take a similar example.
#include <iostream>
using namespace std;
template<class Type>
class dimensioned {
Type value_;
public:
Type& value() { return value_;}
};
int main() {
int Rvalue=1;
dimensioned<int> myType;
myType.value()=Rvalue;
return 0;
}
In the above examle, the member function of value() cannot be used without class name. But in the function of setTime it was called without class name. I am looking forward to your kind reply because I am a beginner of C++.

herbert November 9, 2010 03:57

Hi,

I think value() can be used in this way, because it is a member of the class itself, even it is not defined in Time explicitly. But this class seems to be somehow derived form dimensionedType and therefore it is known.

It just the same as setControls() is used. (without object because it should work on object itself).

Regards,
Stefan

sblee1977 November 9, 2010 04:52

Re_questions
 
Quote:

Originally Posted by herbert (Post 282710)
Hi,

I think value() can be used in this way, because it is a member of the class itself, even it is not defined in Time explicitly. But this class seems to be somehow derived form dimensionedType and therefore it is known.

It just the same as setControls() is used. (without object because it should work on object itself).

Regards,
Stefan

Thank you for your reply.
My limited knowledge of C++ does not makes me fully understand your reply yet. It is clear that both setControls() and setTime() are used without instance because they are defined inside Time class. But value() is defined in dimensioned<Type> class (not in Time class), so I think that value() could be called in Time class with instance as following
dimensioned<scalar> myType;
myType.value();

Thank you for your reply in advance...


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