mercredi 17 août 2016

invalid use of static data member in constructor parameter list

I have a class something like this:

class Foo : public Bar {
double v1;
double v2;
...
public:
explicit Foo (double v1_ = 1.0, double v2_ = v1 > 0.0 ? 2.0 : 0.0)
    : v1(v1_), v2(v2_)
{
    // do something
}

// do other things

};

but I get the following compile error like so:

error: invalid use of non-static data member Foo::v1
note: declared here
double v1;
       ^

Any suggestions are appreciated to get around this error. Also, please point out the mistake in my code and explain a little so that I can understand better. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire