I can’t figure out whats wrong with the code here, so I was hopinh someone could help me out:
In a header file, I define the following functions
void GenLiveVar(const instr_ptr instr, std::vector<ResultBase*> &list);
void KillLiveVar(const instr_ptr instr, std::vector<ResultBase*> &list);
In a class header file, I define this typedef:
typedef boost::function<void(instr_ptr, std::vector<ResultBase*>) > GenFunction;
inside the class, I have two instances of GenFunction
GenFunction Gen;
GenFunction Kill;
And I assign into them as follows
void DataFlowSolver::SetGenFunction(GenFunction &func)
{
Gen = func;
}
void DataFlowSolver::SetKillFunction(GenFunction &func)
{
Kill = func;
}
later in my program, I assign to gen as follows:
blockSolver.SetGenFunction(GenLiveVar);
where GenLiveVar is the function mentioned earlier and blockSolver is an instance of the class holding the Gen/Kill. Inside blockSolver, I do the following:
std::vector<ResultBase*> genList;
Gen(currentBlock->GetInstrPtr(i), &genList);
and GetInstrPtr is defined as const instr_ptr GetInstrPtr(int index);
It generates the follwoing error (sorry for length)
no match for call to '(GenFunction) (const instr_ptr, std::vector<ResultBase*, std::allocator<ResultBase*> >*)'
/nfs/ug/homes-2/r/rileyjon/ece540/Final/boost/function/function_template.hpp:1007:
note: candidates are: typename boost::function2<R, T1, T2>::result_type boost::function2<R, T1, T2>::operator()(T0, T1) const [with R = void, T0 = boost::shared_ptr<Instruction>,
T1 = std::vector<ResultBase*, std::allocator<ResultBase*> >
]
I dont really understand why this is a problem: the types are definitely the same. Some help would be appreciated. Thanks
The types are definitely not the same.
The argument you are passing is of type
std::vector<ResultBase*>*(a pointer):The corresponding parameter is of type
std::vector<ResultBase*>(a value):Also note the mismatch in parameter types between the
boost::function, which takes the second argument by value, and the two functions you assign to it, which take their second arguments by reference. This probably won’t give you the behavior you expect.