I want to use memcpy within class template. So my template will be limited to any link to C POD (structure) and char* (and ofcourse structures can be declared in other independent classes). I want any class to be able to subscribe its function (if it has respectful input args) to cast event. So my class now looks like:
class IGraphElement{
typedef void FuncCharPtr(char*, int) ;
public:
void Add(FuncCharPtr* f)
{
FuncVec.push_back(f);
}
void CastData(char * data, int length){
for(size_t i = 0 ; i < FuncVec.size(); i++){
char* dataCopy = new char[length];
memcpy(dataCopy, data, length);
FuncVec[i](dataCopy, length);
}
}
private:
vector<FuncCharPtr*> FuncVec ;
};
generally I want 2 things that are really one (I try to explain in pseudocode):
template < typename GraphElementDatataStructurePtrType>
class IGraphElement{
typedef void FuncCharPtr(GraphElementDatataStructurePtrType, int) ; // here I want FuncCharPtr to be of type (AnyClassThatWantsToConnectToThisGraphElement::*)(GraphElementDatataStructurePtrType, int)
public:
void Add(FuncCharPtr* f)
{
FuncVec.push_back(f);
}
void CastData(GraphElementDatataStructurePtrType data, int length){
for(size_t i = 0 ; i < FuncVec.size(); i++){
GraphElementDatataStructurePtrType dataCopy = new GraphElementDatataStructurePtrType[length];
memcpy(dataCopy, data, length);
FuncVec[i](dataCopy, length);
}
}
private:
vector<FuncCharPtr*> FuncVec ;
};
Is what I desire any how possible and how to implement it into my class? (sorry - I am a c++ nube=()