I have a problem where.. Well, I'm not sure. I really don't know what it means. I have used this same paradigm illustrated below, where I create an object within a class and give that object a reference to the class. This design is used as an event handler.
I added a very unrelated piece of code where I loop through a map of objects and re-assign them. It has brought up an issue due to the use of the =
operator. But I still don't actually know what it's complaining about.
// Example program
#include <iostream>
#include <string>
#include <map>
class A {
public:
class Handler {
public:
Handler(A &a):a(a){}
virtual void HandleIt(){
a.DoThings();
}
A &a;
};
A():my_handler(*this){}
Handler my_handler;
void DoThings(){
std::cout << "Im doing things";
}
};
std::map<std::string, A> my_map;
void ReplaceInMap(A &a){
std::map<std::string, A>::iterator it;
for(it = my_map.begin(); it != my_map.end(); ++it){
it->second = a;
}
}
int main()
{
A a;
A b;
A c;
my_map.insert(std::make_pair<std::string, A>("A!", a));
my_map.insert(std::make_pair<std::string, A>("B!", b));
my_map.insert(std::make_pair<std::string, A>("C!", c));
ReplaceInMap(a);
}
C++ 98
In member function 'A::Handler& A::Handler::operator=(const A::Handler&)':
8:15: error: non-static reference member 'A&A::Handler::a', can't use default assignment operator
In member function 'A& A::operator=(const A&)': 6:7:
note: synthesized method 'A::Handler& A::Handler::operator=(const A::Handler&)' first required here
In function 'void ReplaceInMap(A&)': 29:20: note: synthesized method 'A& A::operator=(const A&)' first required here
What does this error mean? What is the problem?