I'm trying to compile the following code but I get this error:
error: no viable conversion from 'unique_ptr' to 'unique_ptr'
What I'm trying to do is create a smart pointer that wraps some objects and then use them as listeners.
#include <iostream>
#include <vector>
#include <memory>
class Table {
public:
struct Listener{
virtual void handle(int i) = 0;
};
std::vector<std::unique_ptr<Listener>> listeners_;
void add_listener(std::unique_ptr<Listener> l){
listeners_.push_back(l);
}
};
struct EventListener: public Table::Listener {
void handle(int e){
std::cout << "Something happened! " << e << " \n";
}
};
int main(int argc, char** argv)
{
Table table;
std::unique_ptr<EventListener> el;
table.add_listener(el);
return 0;
}
Any ideas will be appreciate!