What double(*y)(double) means?

Hi all,

Could some one please explain a little bit of whats happening in this code, specially the argument of of the class constructor. What double(*y)(double) means?

Thanks in advance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class FunctionData: public QwtSyntheticPointData
{
public:
    FunctionData(double(*y)(double)):
        QwtSyntheticPointData(100),
        d_y(y)
    {
    }

    virtual double y(double x) const
    {
        return d_y(x);
    }

private:
    double(*d_y)(double);
};
Pointer to a function which takes a double as an argument and returns a double
Thanks mik2718,

And could you please tell me a little bit of what's going on in the constructor of the class, it's a inheritance case or may be d_y is receiving y as a parameter and ... ?

I want to split this into .h + .cpp files, for that I've tried the code that follows but compiler is returning

1
2
3
widget.cpp:80: error: no matching function for call to 'FunctionData::FunctionData(double (&)(double))'
functiondata.h:7: note: candidates are: FunctionData::FunctionData()
functiondata.h:5: note:                 FunctionData::FunctionData(const FunctionData&)


1
2
3
4
5
6
7
8
9
10
class FunctionData
{
public:
    FunctionData();

    virtual double y(double);

private:
    double (*d_y)(double);
};


1
2
3
4
5
6
7
8
9
10
#include "functiondata.h"

FunctionData::FunctionData(double(*y)(double)): QwtSyntheticPointData(100), d_y(y)
{
}

double FunctionData::y(double x)
{
    return d_y(x);
}
Last edited on
Topic archived. No new replies allowed.