virtual function problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adina
    New Member
    • Mar 2007
    • 9

    #1

    virtual function problem

    Hi,
    I have 2 classes in my application: class A and class B.
    in CaptureDoc.h
    Code:
    class CCaptureDoc : public CWinpcap
    {
    public:
    	CCaptureDoc(wxFrame* capframe, CCaptureWindow* capwindow);
    	
    	 void PacketHandler(struct pcap_pkthdr* pkt_header, const unsigned char* pkt_data);
    											 
    	void WinpcapThreadEnded();
    
    	bool m_capmaxperform;
    private:
    	CCaptureWindow* m_capwindow;
    	wxFrame* m_capframe;
    };
    in CaptureDoc.cpp
    Code:
    #include "CaptureDoc.h"
    
    CCaptureDoc::CCaptureDoc(wxFrame* capframe, CCaptureWindow* capwindow)
    {
       /* here some code */
    }
    
    void CCaptureDoc::PacketHandler(struct pcap_pkthdr* packet_header, const unsigned char* packet_data)
    {
    /* here some code */
    }
    
    void CCaptureDoc::WinpcapThreadEnded()
    {
    	/* here some code */
    }
    in winpcap.h
    Code:
    class CWinpcap : public wxThread, wxEvtHandler {
    /* ... code*/
    virtual void PacketHandler(struct pcap_pkthdr* pkt_header, const unsigned char* pkt_data);
    virtual void WinpcapThreadEnded(); 
    /* code */
    }
    In winpcap.cpp member functions of the CWinpcap class are supposed to call the functions WinpcapThreadEn ded() and PacketHandler()

    I need the overriden functions in the derived class to get called by the base class and do their job. Is this the right way to solve this problem. However, I get an error LNK2001: unresolved external symbol....

    If it cannot be done in this way, what would another way be ?
    Any help would be very appreciated :)

    Thanks,
    Adina
  • adina
    New Member
    • Mar 2007
    • 9

    #2
    An observation to the above post: I don't want the base class to know who is inheriting from it. Therefore I don't instantiate a derived class object or something like it. I suppose that you may see the functions overriden in the derived class as callback functions. Is this possible to be done ?

    Thanks,

    Adina

    Comment

    • adina
      New Member
      • Mar 2007
      • 9

      #3
      Hello again,
      I've been reading a little about the template method design pattern.
      I have put the two virtual functions WinpcapThreadEn ded() and PacketHandler() in the base class as protected.
      The functions from the base class that call these two functions are public and non-virtual.

      Stiil I receive the same linking errors: error LNK2001 unresolved external WinpcapThreadEn ded() and unresolved external PacketHandler() .

      Any ideas to this problem are very much welcomed.

      Thanks,
      Adina

      Comment

      Working...