Thread: virtual members redefinition

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    5

    Question virtual members redefinition

    Hi all,

    how can I must redefine a virtual function member to return different values from the derived classes ???

    i.e :

    class population
    {
    public :
    virtual getindividual();
    }

    class subpopulation1 : public population
    {
    public :
    (type1 *) getindividual();
    }

    class subpopulation2 : public population
    {
    public :
    (type2 *) getindividual();
    }

    Is this well done ?

    Thanks for your knowledge.

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    I'm not sure what you're up to, but you could use templates to overload on return type -

    Code:
    template <class T>
    class population 
    { 	
    public : 
    	virtual T getindividual(){return 0;} 
    }; 
    
    template <class T>
    class sub:public population<T>
    {
    public:
    	T getindividual(){return 0;}
    };
    int main()
    {
    	population<int>* p = new sub<int>;
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  3. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM