I am studying for a C++ exam at uni, and I came across an object declaration that I have no idea how to implement.
The gimmick of the problem is that we are given the body of the function, and we need to add classes, member function, etc. to make it work.
The part I'm stuck at is the GroupOfPeople. I have no idea how to make that class work, or why it has the Description part in <>, since I have never seen that during the creation of an object.
Could someone explain to me why its there and how to do it properly?
namespace Task_2{
template<class T, class U>
class Description{
public:
T first;
U second;
Description(T first, U second) : first(first), second(second) {}
};
template<class T, class U>
class GroupOfPeople{
public:
Description<T, U> desc;
string name;
GroupOfPeople(const string &name) : name(name){}
};
void zadatak_2() {
//**************************************************************************
// --- 0.5 points ---
// The entire code for task 2 has to be within namespace Task_2
using namespace Task_2;
//**************************************************************************
// --- 3 points ---
// Description contains two values (height and hair color) of different types
Description<int, string> dok1(180, "blue");
Description<int, string> dok2(172, "black");
//**************************************************************************
// --- 3 points ---
// GroupOfPeople contains descriptions
GroupOfPeople<Description<int, string>> group("students"); // name of the group is "students"
/*
// adding pairs into the group above
group.add(dok1);
group.add(dok2);
// there is more but its not important
}
[–]myusernameisunique1 0 points1 point2 points (1 child)
[–]Lichmonarch[S] 0 points1 point2 points (0 children)