//main.h #if !defined(MAIN_H) #define MAIN_H namespace test { class BASE { public: BASE() { } BASE(int val) { this->m_val = val; } virtual ~BASE() { } virtual int func(int val); int m_val; }; class DERIVED : public BASE { public: DERIVED() : BASE() {} DERIVED(int val) : BASE(val) {} virtual ~DERIVED() {} int func(int val); }; } #endif //MAIN_H //main.cpp #include "main.h" namespace test { int BASE::func(int val) { return 0; } int DERIVED::func(int val) { this->m_val = val; } int main() { int tmp; BASE b; DERIVED d(tmp); return 0; } }