CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   dimensionedScalar as class member (https://www.cfd-online.com/Forums/openfoam-programming-development/115257-dimensionedscalar-class-member.html)

Seeker March 27, 2013 03:04

dimensionedScalar as class member
 
Hi!

I am trying to write a small class. I feel like this should be trivial, but I can't figure out how to get a dimensionedScalar as a class member without errors =/.

I would like to have something along the lines of:
Code:

class A {
    public:
        A();
        ~A() {};
        dimensioned<scalar> getX() {return dimX; } //Edited
    private:
        dimensioned<scalar> dimX();
}

//Constructor
A::A () {
    dimX.name() = "dimX";
    dimX.dimensions() = dimLength;
    dimX.value() = 0.0;
}

Instead of having a dimensionedScalar, I can of course just have a double as class member and than have a dimensionedScalar created and returned when getX() is called... but that's really not pretty =).

The error I am getting is "error: ‘((A*)this)->A::dimX’ does not have class type"

What am I missing?
Thanks!

l_r_mcglashan March 28, 2013 13:40

Is that the actual code you're trying to compile?

Your function getX has no return value and the member variable dimX should not have brackets after it for a start.

Seeker March 29, 2013 05:57

Hi
Thanks for the reply

I typed it up in here, forgot to copy the returntype, thanks.

Quote:

member variable dimX should not have brackets after it for a start.
That's the way I had it at the beginning too. In this case however, without brackets I get this:
error: no matching function for call to ‘Foam::dimensioned<double>::dimensioned()’

I looked up the source code and found that a NULL constructor is called with empty brackets, which seems to work. However, I cannot seem to be able to assign any value afterwards.


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