abstact class in c++


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: abstact class in c++

  1. #1
    farah Guest

    abstact class in c++


    the compiler does not gives an error if we create an object of abstract class
    in c++ so does that means that every base class whose object we don't declare
    is an abstract class?
    whats the main difference between the normal base class and abstract base
    class?

  2. #2
    Vijay Guest

    Re: abstact class in c++


    "farah" <f_sulemani@yahoo.com> wrote:
    >
    >the compiler does not gives an error if we create an object of abstract

    class
    >in c++ so does that means that every base class whose object we don't declare
    >is an abstract class?
    >whats the main difference between the normal base class and abstract base
    >class?


    In C++ a class becomes a abstarct when it any pure virtual function
    functions like this
    void show()=0;
    u can't create objects of class which has this type function.





  3. #3
    Sheshadri Iyengar Guest

    Re: abstact class in c++

    farah wrote:

    > the compiler does not gives an error if we create an object of abstract class
    > in c++ so does that means that every base class whose object we don't declare
    > is an abstract class?


    No, it is not.

    >
    > whats the main difference between the normal base class and abstract base
    > class?


    A class which has, atleast one pure virtual function is called an abstract class.

    If you mean normal base class as an non-abstract class, then the non-abstract
    class doesn't have a pure virtual function.

    For ex:
    class A
    {
    virtual void fun() = 0;
    };

    Here class 'A' is an abstract class as it has a function 'fun', which is a pure
    virtual function.(at least one).

    A a1; // Wrong, Cannot create the object.

    A* a1; // Correct, because of using.

    shesh


  4. #4
    mohit Guest

    Re: abstact class in c++


    The post below is not for Farah coz I don't want to confuse her with complex
    stuff.

    >A class which has, atleast one pure virtual function is called an >abstract

    class.
    ........
    An abstract class is one which cannot be instantiated. I think it is incorrect
    to say that the class should have atleast one pure virtual function.
    Abstract classes can also be created by having protected constructors. These
    constructors should be called through protected static functions by the derived
    classed.
    -mohit


    Sheshadri Iyengar <sheshadri.i@kshema.com> wrote:
    >farah wrote:
    >
    >> the compiler does not gives an error if we create an object of abstract

    class
    >> in c++ so does that means that every base class whose object we don't

    declare
    >> is an abstract class?

    >
    >No, it is not.
    >
    >>
    >> whats the main difference between the normal base class and abstract base
    >> class?

    >
    >A class which has, atleast one pure virtual function is called an abstract

    class.
    >
    >If you mean normal base class as an non-abstract class, then the non-abstract
    >class doesn't have a pure virtual function.
    >
    >For ex:
    > class A
    > {
    > virtual void fun() = 0;
    > };
    >
    >Here class 'A' is an abstract class as it has a function 'fun', which is

    a pure
    >virtual function.(at least one).
    >
    > A a1; // Wrong, Cannot create the object.
    >
    > A* a1; // Correct, because of using.
    >
    >shesh
    >



  5. #5
    Danny Kalev Guest

    Re: abstact class in c++



    mohit wrote:
    >
    > The post below is not for Farah coz I don't want to confuse her with complex
    > stuff.
    >
    > >A class which has, atleast one pure virtual function is called an >abstract

    > class.
    > .......
    > An abstract class is one which cannot be instantiated. I think it is incorrect
    > to say that the class should have atleast one pure virtual function.

    Indeed. Abstract classes are a design concept which has at least two
    syntactic manifestations: a class with at least one pure virtual member
    function and -- in more advanced programming tasks and design patterns
    -- a class with a protected ctor. In either case the intent is the same:
    to avoid instantiation of the class, while allowing derived classes to
    implement its interface. The compiler disables any attempt to
    instantiate an abstract class but it's perfectly legal to use pointers
    and references to such a class.

    Danny

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center