c++ - How do I resolve the "undefined reference to `vtable for <<ClassName>>" error? -
i c++ beginner. have singleton 'manager' class shown below , following error when build project in eclipse:
../src/manager.hpp:28: undefined reference 'vtable manager'
[the below code minimum (almost) run in dev environment or ides if want try , reproduce error.]
manager.hpp
#include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <unistd.h> #include "stream_state.h" class manager { public: static manager* getinstance(); std::vector<stream_state> m_statelist; // why can not remove std::? virtual ~manager(); // virtual destructor private: manager(){}; // error points here - why so? manager(manager const&){}; static manager* psingleton; }; manager.cpp
#include "manager.hpp" manager* manager::psingleton = 0; manager* manager::getinstance() { if (psingleton == null){ psingleton = new manager; } return psingleton; } // other member function implementations main.cpp
#include <iostream> #include <stdlib.h> #include "manager.hpp" int main(int argc, char** argv) { manager* managerobj; managerobj = manager::getinstance(); // other code return 0; } stream_state.h
struct stream_state { file* sp; bool locked; }; what have tried (and didn't work):
1. changed constructor manager class to:
manager::manager(){}; error: extra qualification 'manager::' on member 'manager'
2. removed std:: line std::vector<stream_state> m_statelist; vector<stream_state> m_statelist; error: vector not name type
can please explain me undefined reference 'vtable manager' error (and, if possible no necessary, vector not name type error)?
i see declaration ~manager() don't see definition. needs in manager.cpp.
i believe getting obscure message because vtable holds addresses of virtual functions. have 1 virtual function , haven't defined it.
i can't reproduce vector error. once add ~manager::manager() { } manager.cpp, version compiles fine.
Comments
Post a Comment