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/)
-   -   expected primary-expression before ..... (https://www.cfd-online.com/Forums/openfoam-programming-development/143814-expected-primary-expression-before.html)

sharonyue November 3, 2014 10:37

expected primary-expression before .....
 
Hi guys,

I added this piece of code into the original one:
Code:

Foam::tmp<Foam::volScalarField> Foam::twoPhaseSystem::dragCoeff() const
{
    return drag_->K();
}

Foam::tmp<Foam::volScalarField> Foam::twoPhaseSystem::dragCoeff(const volScalarField& M30, const volScalarField& M20) const
{
    return drag_->K(const volScalarField& M30, const volScalarField& M20);
}

the compiler said:
Code:

twoPhaseSystem.C: In member function ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> > Foam::twoPhaseSystem::dragCoeff(const volScalarField&, const volScalarField&) const’:
twoPhaseSystem.C:291:21: error: expected primary-expression before ‘const’
    return drag_->K(const volScalarField& M30, const volScalarField& M20);
                    ^
twoPhaseSystem.C:291:48: error: expected primary-expression before ‘const’
    return drag_->K(const volScalarField& M30, const volScalarField& M20);
                                                ^
twoPhaseSystem.C:292:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
make: *** [Make/linux64GccDPOpt/twoPhaseSystem.o] Error 1

Even I change it into:
Code:

Foam::tmp<Foam::volScalarField> Foam::twoPhaseSystem::dragCoeff() const
{
    return drag_->K();
}

Foam::tmp<Foam::volScalarField> Foam::twoPhaseSystem::dragCoeff(const volScalarField& M30, const volScalarField& M20) const
{
    return drag_->K(int A);
}

It crushed!!

But this is totally fine:
Code:

Foam::tmp<Foam::volScalarField> Foam::twoPhaseSystem::dragCoeff() const
{
    return drag_->K();
}

Foam::tmp<Foam::volScalarField> Foam::twoPhaseSystem::dragCoeff(const volScalarField& M30, const volScalarField& M20) const
{
    return drag_->K();
}

So it must be something wrong with this:
Code:

return drag_->K(const volScalarField& M30, const volScalarField& M20);

or

return drag_->K(int A);

But I dont know where its wrong. Any comments is appreciated!
Thanks

floquation November 4, 2014 03:11

Quote:

Originally Posted by sharonyue (Post 517166)
So it must be something wrong with this:
Code:

return drag_->K(const volScalarField& M30, const volScalarField& M20);

or

return drag_->K(int A);


Indeed.
You need to distinguish parameter passing and receiving.

When you receive a parameter in a function (blue, below), you must specify its type. You are already doing this.
When you pass a variable to another function (purple, below), you must solely pass the variable, without including its type in front: the compiler already knows its type. If you do put its type in front, you are declaring a new variable, which you do not initialize. That will result in a compilation error.

Quote:

Originally Posted by sharonyue (Post 517166)
Code:


Foam::tmp<Foam::volScalarField>  Foam::twoPhaseSystem::dragCoeff(const volScalarField& M30, const  volScalarField& M20) const
{
    return drag_->K(const volScalarField& M30, const volScalarField& M20);
}


So, you should do:

Code:


Foam::tmp<Foam::volScalarField>  Foam::twoPhaseSystem::dragCoeff(const volScalarField& M30, const  volScalarField& M20) const
{
    return drag_->K(M30, M20);
}


sharonyue November 4, 2014 03:23

Exactly! Thank you very much!!!!!!!!!
bro!!


All times are GMT -4. The time now is 23:48.