I have a class with a std::map
used as a container. I want to add a function to copy the map between two objects. Since the map was declared as a private member of the class, I need a friend function to do so. Here is my code:
class Data;
void copyData(Data &, Data &);
class Data
{
private:
map<int, int> _data;
public:
friend void copyData(Data &, Data&);
};
void copyData(Data &a, Data &b)
{
std::copy(a._data.begin(), a._data.end(), b._data.begin());
}
main()
{
// initialization here
Data A, B;
copyData(A, B);
}
But there are many warnings while compiling with mingw32. How do I do this correctly?