CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   dimensionedScalar as class member (

Seeker March 27, 2013 04:04

dimensionedScalar as class member

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:

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

A::A () { = "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?

l_r_mcglashan March 28, 2013 14: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 06:57

Thanks for the reply

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


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 06:11.