CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2008
    Posts
    48

    Is there anything like Virtual Class present ?

    Hi,
    Is there any concept called 'Virtual Class' present in C++ ?

    Thanks
    Kiran

  2. #2
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    Re: Is there anything like Virtual Class present ?

    Not by that name. What does it mean?
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


  3. #3
    Join Date
    Apr 2007
    Location
    Mars NASA Station
    Posts
    1,436

    Re: Is there anything like Virtual Class present ?

    Yes, by with different name.

  4. #4
    Join Date
    Sep 2008
    Posts
    48

    Re: Is there anything like Virtual Class present ?

    What is it ?

    Is it mean by inheriting a base class as Virtual one ?

  5. #5
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    Re: Is there anything like Virtual Class present ?

    If Virtual class is something like an abstract base class then there´s an equivalent in C++. Unlike as in java you don´t have to mark the abstract base class, all you have to do is to declare a pure virtual function and the class is automatically abstract.

    Code:
    /*no keyword needed here*/ class AbstractBaseClass
    {
    public:
       AbstractBaseClass();
       virtual ~AbstractBaseClass();
    
       // pure virtual function declaration makes this class virtual/abstract
       virtual func() = 0;
    };
    
    class ConcreteClass : public AbstractBaseClass
    {
    public:
       ConcreateClass();
    
       // implementation of inherited pure virtual function
       void func();
    };
    Last edited by GNiewerth; October 8th, 2008 at 04:53 AM.
    - Guido

  6. #6
    Join Date
    Nov 2003
    Posts
    1,405

    Re: Is there anything like Virtual Class present ?

    Quote Originally Posted by rsodimbakam
    What is it ?

    Is it mean by inheriting a base class as Virtual one ?
    I guess you could call a class virtual if it contains virtual functions. If all functions are pure virtual you could call the class abstract or an interface.

    Then there's something called virtual inheritance. It's a way do avoid problems with multiple copies of the same class in a multiple inheritance situation. A class can be declared to be virtually inherited by the inheriting class.
    Last edited by _uj; October 8th, 2008 at 11:33 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