I have two classes, Sim and IElement. The class IElement defines a function pointer, whereas the class Sim has a vector of IElement pointers. What is the correct way to call the pointed-to function from the function pointer defined in IElement, given that I have a vector of IElement*?
Or in another words, I have
std::vector<IElement*> nodes;
And I need to call a pointed-to function from IElement:
nodes[i]->*SetInput(); // ERROR: Identifier "SetInput" is undefined
I assume I'm having this error because nodes is a vector of pointers, and I am unaware of how to dereference nodes[i] before calling its pointed-to function.
Thank you for any advice.
A bit more detailed snippets of the code are given below.
The method of the Sim class where I am having the error Undefined identifier for the method of IElement
#include <vector>
#include "Elements.h" // defines class IElement in namespace Elements
void Sim::CreateNodes(int N) // this method belongs to the Sim class in namespace "Simulations"
{
nodes = std::vector<Elements::IElement*>(N);
int i = 0;
while (i < N)
{
nodes[i] = new Elements::IElement(true); // for the sake of the example
nodes[i]->*SetInput(); // ERROR: Identifier "SetInput" is undefined
i++;
}
}
whereas in the Elements namespace, I have the class IElement declaration
class IElement
{
public:
typedef void(IElement::*SetInputFc_ptr)();
IElement(bool); // normalizeInput
~IElement();
SetInputFc_ptr SetInput;
};
and the class IElement implementation
IElement::IElement(bool normalizeInput)
{
if (normalizeInput)
{
this->SetInput= &(this->SetInput_Sum);
}
else
{
this->SetInput= &(this->SetInput_Const);
}
}