Hello,
I need to use pointer to members and retrieve the value (a double) that these members should return. But I have a compile error:
#include <vector>
class B {
double _mean, _mean2;
enum { cnt = 2 };
public:
double (B::*fptr[cnt])(void) const;
B() {
fptr[0] = &B::getMean;
fptr[1] = &B::getMean2;
}
double getMean() const { return _mean; }
double getMean2() const { return _mean2; }
};
class A {
public:
std::vector<B> _vec;
};
//main.cpp
B objB;
A objA;
double db = objA._vec.at(0).fptr[0]; //here error; doens't B::mean() return a double?
#include <vector>
class B {
double _mean, _mean2;
enum { cnt = 2 };
public:
double (B::*fptr[cnt])(void) const;
B() {
fptr[0] = &B::getMean;
fptr[1] = &B::getMean2;
}
double getMean() const { return _mean; }
double getMean2() const { return _mean2; }
};
class A {
public:
std::vector<B> _vec;
};
//main.cpp
B objB;
A objA;
double db = objA._vec.at(0).fptr[0]; //here error; doens't B::mean() return a double?
To copy to clipboard, switch view to plain text mode
//error:
error C2440: 'initializing' : cannot convert from 'double (__thiscall B::* )(void) const' to 'double'
//error:
error C2440: 'initializing' : cannot convert from 'double (__thiscall B::* )(void) const' to 'double'
To copy to clipboard, switch view to plain text mode
Maybe i', using it in a wrong way.....how can I do this thing, please?
Bookmarks