Thread: Abstract inheritence

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    "Why use dynamic memory?"
    Join Date
    Aug 2006
    Posts
    186
    why would you do that ??
    abstract class is already an abstract class, one I think should be enough because after all it's generic and should contain all functions

    multiple inheritance can cause confusion
    "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."-Bjarne Stroustrup
    Nearing the end of finishing my 2D card game! I have to work on its 'manifesto' though <_<

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Sure it's possible. You might want an abstract subclass to provide a partial default implementation. Even if you don't provide a default impl, you may want to extend the interface.

    Code:
    #include <iostream>
    
    class A {
    public:
        virtual void func1() = 0;
        virtual void func2() = 0;
    };
    
    class B : public A {
    public:
        virtual void func2() 
        {
    	std::cout << "B::func2()" << std::endl;
        }
    };
    
    class C : public B {
    public:
        virtual void func1() 
        {
    	std::cout << "C::func1()" << std::endl;
        }
    };
    
    int main()
    {
        A * c = new C;
        // Can't do this, because B is abstract
        // A * b = new B;  
    
        c->func1();
        c->func2();
    }
    $ g++ abstract.cpp
    $ a.out
    C::func1()
    B::func2()
    $
    Last edited by medievalelks; 06-18-2009 at 08:36 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Abstract or Interface?
    By audinue in forum Tech Board
    Replies: 6
    Last Post: 07-02-2009, 07:09 AM
  2. Abstract constructor
    By Shal in forum C++ Programming
    Replies: 9
    Last Post: 05-18-2006, 01:14 PM
  3. Abstract Factory pattern
    By Just in forum C++ Programming
    Replies: 3
    Last Post: 02-18-2005, 10:58 AM
  4. abstract class
    By xddxogm3 in forum C++ Programming
    Replies: 5
    Last Post: 01-01-2005, 09:08 AM
  5. abstract vs pure abstract class
    By Kohatian 3279 in forum C++ Programming
    Replies: 2
    Last Post: 05-10-2002, 11:12 AM