#include<iostream>
class base{
public:
virtual void run()=0;
protected:
~base();
};
class derived : public base {
public:
void run(){};
~derived();
};
int main(){
std::shared_ptr<base> b;
b.reset(new derived);
b->run();
}
I have an abstract base class and derived class from it. In main, I define a shared pointer and allocate it with derived type. Then, I use the virtual function. If I comment out b.reset(new derived) then it works fine. The error message is
Undefined symbols for architecture x86_64: "derived::~derived()", referenced from: std::__1::shared_ptr::shared_ptr(derived*) in test-274b97.o std::__1::__shared_ptr_pointer, std::__1::allocator >::__on_zero_shared() in test-274b97.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any answer will be appreciated!
Thanks.