General explanation of program design.
It is a student registration program. Registration is the top object in the hierarchy it contains a vector of result objects. Result object contains a mark, date object and a string unitId.
This string is used to access a binary search tree. The binary search tree is of a object unit, the operator are overloaded to compare the id.
My problem is such. I'm looking for a way for registration class to the data it has access to std::string unitId (via a result object) to set a temporary unit object to run calculations on.
I've tried doing this by passing the a (BSTree& Tree) as a parameter but my map.. excuse lack of precise explanation, has a cry and says that all the functions have already been defined and I also get errors that my unit comparison operators don't deal with (unit U1, const Unit u2) - it gets really messy it seems.
As such I've tried to learn and used std::bind and placeholders.
Main pieces of code are as follows:
using namespace std::placeholders;
Unit& accessTree(std::string id, BSTree<Unit>& tree);
template<typename Ft>
unsigned Registration::GetCredits(Ft func)
{
unsigned sum = 0;
for(unsigned i = 0; i < GetSize(); i++)
sum += results[i].GetCredits(func(results[i].GetUnit()));
return sum;
}
int main()
{
BSTree<Unit> uTree;
Result Re;
Re.SetUnit("ICT210");
Re.SetMark(70);
Registration R;
R.SetResult(Re, 0);
Unit u0;
u0.SetId("ICT210");
u0.SetName("Rikki Testing");
u0.SetCredits(4);
uTree.insert(u0);
R.GetCredits(std::bind(accessTree, _1, std::ref(uTree)));
return 0;
}
The Error I get:
undefined reference to `unsigned int Registration::GetCredits(std::_Placeholder<1>, std::reference_wrapper >))(std::string, BSTree&)> >(std::_Bind(std::_Placeholder<1>, std::reference_wrapper >))(std::string, BSTree&)>)'|
Aucun commentaire:
Enregistrer un commentaire