C++ knowledge

This is a discussion on C++ knowledge within the C++ Programming forums, part of the General Programming Boards category; Tell me what is the basic difference between a virtual base class and an abstract base class....

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    1

    Lightbulb C++ knowledge

    Tell me what is the basic difference between a virtual base class and an abstract base class.

  2. #2
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    Never heard of it
    what does signature stand for?

  3. #3
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    A virtual class is a class with a virtual function. An abstract class is a class that has a pure virtual function. One cannot create abstract classes (only subclasses of abstract classes). However, non-abstract virtual classes can be instantiated. Confusing enough? .

    Code:
    class virtualClass {
    public:
        virtual void someVirtualFunc();
    };
    
    class abstractClass {
    public:
         virtual void pureVirtualFunc()=0;
    };
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  4. #4
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    Yea, that IS confusing...
    what does signature stand for?

  5. #5
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    >> Yea, that IS confusing...

    Well, not really. Its actually quite logical.

    eg.
    Code:
    class Teacher
    {
    public:
        virtual void Teacher();
    
        char fname[256];
        char sname[256];
        
        virtual void TeachClass();
    }
    In the above class we have an abstract class called teacher. It has its contructor and a pure virtual function called 'TeachClass()'. Obviously this function would be differernt according to each different type of teacher (eg. Science teacher). The science teacher would be a subclass of Teacher and it would overload the pure virtual functions with their own version of them like the following.
    Code:
    class ScienceTeacher : public Teacher
    {
        void TeachClass()
        {
            // do special science stuff
        }
    }
    Its not that confusing after all

  6. #6
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    You're wrong... it's SO Confusing!!
    what does signature stand for?

  7. #7
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    Don't fret... it'll just take some time to 'click' with you I guess... It makes sense though!

    In face_master's example, TeachClass() is virtual function member of Teacher, which means that when you derive a class from Teacher (excuse the terminology ) TeachClass() can be redefined to fit that class if it chooses not to use the default from Teacher if it's defined

  8. #8
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    I just read what I posted and I think I probably confused you more

    Look at some tutorials...

    One other thing... you cannot create instances of abstract classes; remember this.
    Code:
    abstractClass ac;
    Cannot be done

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Confusing enough? .
    Only to those who do not already understand it. This seems to be the case with almost everything in C++.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Too much knowledge hindering you?
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 09-02-2008, 05:23 PM
  2. Putting Programming Knowledge To Practise
    By DanMarionette in forum C++ Programming
    Replies: 5
    Last Post: 07-28-2007, 05:40 AM
  3. C++ Knowledge Needed For Making Graphic Games?
    By Krak in forum C++ Programming
    Replies: 14
    Last Post: 07-11-2003, 09:11 PM
  4. knowledge resource for linux programming
    By Jaguar in forum Linux Programming
    Replies: 1
    Last Post: 11-03-2002, 11:46 AM
  5. knowledge corrupts
    By Sentaku senshi in forum A Brief History of Cprogramming.com
    Replies: 63
    Last Post: 06-07-2002, 11:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21