what correct way use inheritance among multiple files?
i new c++, , trying create class gdi+ related functions i'm gonna use in separate cpp files. have tried several approaches , able find problem more got trying empty constructor.
i lnk2019 code (i took away parts unrelated issue, related wndfuncs class left):
header of functions file:
#ifndef wndfuncs_h #define wndfuncs_h class wndfuncs { private: public: wndfuncs(); //declaration }; #endif
the file itself:
#include "stdafx.h" #include <windows.h> #include <commctrl.h> #include <winuser.h> #include <gdiplus.h> #include "wndfuncs.h" wndfuncs::wndfuncs() //definition { }
the header of class tries inherit class:
#ifndef searcheditbox_h #define searcheditbox_h class searcheditbox : public wndfuncs { private: wndfuncs b; searcheditbox(); public: ~searcheditbox(); static searcheditbox* createeditbox(hinstance hinst, hwnd hwnd, int pos_x, int pos_y, int width, int height, wndcols const* p_wndcols); #endif
the class file:
#include "stdafx.h" #include "wndcols.h" #include <windows.h> #include "wndfuncs.h" #include "searcheditbox.h" searcheditbox::searcheditbox() : b() { } searcheditbox::~searcheditbox() { if (editbox) destroywindow(editbox); } searcheditbox* searcheditbox::createeditbox(hinstance hinst, hwnd hwnd, int pos_x, int pos_y, int width, int height, wndcols const* p_wndcols) { searcheditbox *p_searcheditbox = new searcheditbox; //allocating dynamic memory class (which declared pointer) return p_searcheditbox; }
the error is:
lnk2019 unresolved external symbol "public: __thiscall wndfuncs::wndfuncs(void)" (??0wndfuncs@@qae@xz) referenced in function "private: __thiscall searcheditbox::searcheditbox(void)" (??0searcheditbox@@aae@xz)
i have read explanation , points on msdn page (even tried putting "__cdecl" function declaration), sure function declared , defined (in class files; tried const int x
thinking problem may in empty constructor), wndfuncs file should fine.
i have read this , assumption declare class in wrong way in inheriting file (and linker can't link correct functions in wndfuncs class), when trying described in here not either. not using virtual members problem should not related (as pointed out on page).
when add destructor wndfuncs class 2 lnk2019 errors, problem should not related also. have header files in right order think (tried both).
i tried other function (with or without constructor) same error.
the problem solved adding class files project correct way: project > add class. after references linked correctly.
what did wrong adding files project separately (through: file > add > file).