Avihai Marchiano
Avihai Marchiano

Reputation: 3927

How ro declare a member which is a pointer to function

#define SYNC_DATA_CB list<string> (*syncData)(void)

I want to have in my class a member (static or not is not matter) that will hold the reference to the function pointer.

I tried to declare like this, but didnt compiled:

SyncProcess{
  public:
   SyncProcess(SYNC_DATA_CB);
   static SYNC_DATA_CB sync_cb_;
}

Upvotes: 0

Views: 64

Answers (3)

Rost
Rost

Reputation: 9089

Use typedef instead of macro:

class SyncProcess
{
public:    

   // Typedef to create function pointer alias SyncDataFunc
   typedef list<string>(*SyncDataFunc)();

   // Use alias as input parameter type
   SyncProcess(SyncDataFunc func);

   // Use alias as static member type
   static SyncDataFunc sync_cb_;
};

Upvotes: 0

nemasu
nemasu

Reputation: 426

I think what you might be looking for is a typedef instead.

typedef list<string>(*syncData)(void);

class SyncProcess{
  public:
   SyncProcess( syncData );
   static syncData sync_cb_;
};

Upvotes: 1

micnyk
micnyk

Reputation: 746

std::function<list<string> (void)> myPointer;

Upvotes: 0

Related Questions