Thread: Keyword 'virtual' and interface class definitions - compiler tolerance

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    210

    Lightbulb Keyword 'virtual' and interface class definitions - compiler tolerance

    Hi there,

    I have a fairly straightforward question. Check out the class below:

    Code:
    class winInterface
    {
    public:
    	virtual ~winInterface();
    	virtual HWND createWindow(HINSTANCE hInstance, WINPROC _winproc, 
    			WCHAR* szTitle, WCHAR* szWindowClass, int nCmdShow) = 0;
    
    	HINSTANCE hInstance;
    	HWND hwnd;
    	WINPROC _winProc;
    	WCHAR szTitle[MAX_LOADSTRING];
    	WCHAR szWindowClass[MAX_LOADSTRING];
    };
    All this works fine. Provides a little interface to a derived class in a DLL which sets up a window (hence the pure virtual function). I noticed though I had terrible trouble yesterday with a linker error when I did not use the virtual keyword.

    One way I got around this was to put a small definition of the function in the shared interface header file, which was to be over-rided later. Now I find since I've upped my game a bit and included the virtual keyword (like I was supposed to) it's no longer an issue.

    None of this is a problem but... does that mean that provided you use the virtual keyword the compiler wont even ask for a function definition anywhere and will just tolerate that? Even though it has no access to the header file specific to the DLL where the function is actually defined? (I've checked that it doesn't).

    I just sorta need to know...for some reason

    Thanks
    Last edited by Salem; 10-21-2023 at 05:29 AM. Reason: Wrapping

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-17-2008, 01:00 PM
  2. Replies: 5
    Last Post: 06-19-2006, 03:43 PM
  3. Virtual Keyword
    By Shal in forum C++ Programming
    Replies: 6
    Last Post: 05-18-2006, 11:37 AM
  4. 'interface' keyword
    By Magos in forum C++ Programming
    Replies: 6
    Last Post: 02-21-2006, 11:15 PM
  5. difference between pure virtual class and interface
    By kmirza in forum C++ Programming
    Replies: 4
    Last Post: 05-19-2003, 05:03 AM

Tags for this Thread