Tuesday, June 26, 2018

c++ - Member-Function Pointer in Threads

I have made a class which uses an array of member-functions to initialize an array of threads.


I do not know how to pass the function pointer to the thread constructor. There is few documentation about this topic.


class.h


#define N_FUNCTIONS 23
class TradingData
{
public:
void EXECUTE();
void Book();
void Charts();
void Company();
void Dividends();
void Earnings();
void EffectiveSpread();
void Financials();
void KeyStats();
void LargestTrades();
void List();
void Logo();
void News();
void OHLC();
void Peers();
void Previous();
void Price();
void Quote();
void Relevant();
void Splits();
void TimeSeries();
void VolumeByVenue();
void S_Previous();
void S_Symbols();
private:
std::thread p_thread[N_FUNCTIONS];
typedef void (TradingData::*overall)();
overall p_overall[N_FUNCTIONS] = {
&TradingData::Book,
&TradingData::Charts,
&TradingData::Company,
&TradingData::Dividends,
&TradingData::Earnings,
&TradingData::EffectiveSpread,
&TradingData::Financials,
&TradingData::KeyStats,
&TradingData::LargestTrades,
&TradingData::List,
&TradingData::Logo,
&TradingData::News,
&TradingData::OHLC,
&TradingData::Peers,
&TradingData::Previous,
&TradingData::Price,
&TradingData::Quote,
&TradingData::Relevant,
&TradingData::Splits,
&TradingData::TimeSeries,
&TradingData::VolumeByVenue,
&TradingData::S_Symbols,
&TradingData::S_Previous
};

class.cpp


void TradingData::EXECUTE()
{
for (int i = 0; i < N_FUNCTIONS; i++) {
p_thread[i] = std::thread((this->*p_overall[i])()); //here is the problem
}
for (int i = 0; i < N_FUNCTIONS; i++) {
p_thread[i].join();
}
std::cout << "finished successfully" <}

I got the next error:
Error C2440 '': cannot convert from 'void' to 'std::thread'

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...