0

I have a class (myClass) that has a pointer to function as private member like this:

void (gi::myClass::*ptrFunction) (int  , int  , vector<int> & , vector<int> & , vector<int> &);

When you create at runtime (with new) a object (a *myClass ptrObject) of myClass this pointer is inizialited in the constructor with the address of a function. After with the same object created above I call another function. In this function I must create a deep copy of the calling object:

gi::myClass *ptrObject2 = new myClass(....);

Above I call a constructor that do the copy but it don't initialize the member *ptrFunction of *ptrObject2 My question is: How do I do a deep copy of the pointer function from the *ptrObject to ptrObject2? (My compiler is C++11)

Nick
  • 1,439
  • 2
  • 15
  • 28

1 Answers1

3

There is no deep-copy of a function pointer. You are not copying any data, just a reference into the v-table. As such:

ptrObject2->ptrFunction = ptrObject->ptrFunction

Is fine.

Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175