I have the following use case,
struct Trans {
double price;
};
struct Quote {
double bid_price_1;
double ask_price_1;
};
template<typename DataT, double DataT::*ptr>
class Return {
public:
void operator()(DataT& data) {
// print out the right field of the right class
//std::cout << &DataT::ptr << std::endl;
}
};
int main() {
Quote quote {1, 2};
Return<Quote, &Quote::bid_price_1> ret;
ret(quote);
}
In the operator
of Return
class, I would like to be able to reference the right member variable of the right class, I have read the following post (Pointer to class member as template parameter), but it does not seem to mention how to retrieve the member variable part. I would like to know what is the right syntax to retrieve the member variable specified at compile time.