CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 17

Threaded View

  1. #1
    Join Date
    Feb 2010
    Posts
    10

    call derived method from base class

    Hi All,

    I'm having troubles achieving something, I need to call an overriden method from the base class as follow :
    Code:
    class Base{
    	public: 
    		void start(){
    			new thread(boost::bind(&Base::run, this));
    		}
    		
    		virtual void go(){
    			// do something
    		}
     
    }
     
     
    class Derived : public Base {
    	public:
    		void go(){
    			//do something different
    		}
    }
     
     
    int main(int argc, char** argv){
    	Derived* der = new Derived();
    	der->start();
     
    	return 0;
    }
    I thought this way the binding is done at runtime, and the method of the base class is called but this is not what I'm getting !!

    Just to discard the boost::bind, I tried this as well :

    Code:
    class Base{
    	public: 
    		void start(){
    			new thread(boost::ref(*this));
    		}
    		
    		virtual void go(){
    			//do something.
    		}
    		
    		void operator()(){
    			this->go();
    		}
     
    }
     
     
    class Derived : public Base {
    	public:
    		void go(){
    			//do something different
    		}
    }
     
     
    int main(int argc, char** argv){
    	Derived* der = new Derived();
    	der->start();
     
    	return 0;
    }
    OS : windows
    COMPILER : gcc

    am I doing something wrong ?

    thanks in advance.

    BR
    Last edited by let_me_in; September 20th, 2010 at 06:23 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured