what is abstract class in c++

//Code by Soumyadeep Ghosh 
//insta : @soumyadepp
//linked in : https://www.linkedin.com/in/soumyadeep-ghosh-90a1951b6/
#include <bits/stdc++.h>

using namespace std;

class person
{
  string p_id;
  public:
  virtual void get_info()=0; //declaring person as abstract class
  virtual void show()=0;
};

class student:public person
{
  string name;
  int roll_no;
  public:
  /*overriding the pure virtual function declared in base class otherwise
    this class will become an abstract one and then objects cannot be created
    for the same*/
    void get_info()
    {
      cout<<"Enter name of the student "<<endl;
      cin>>name;
      cout<<"Enter roll number of the student "<<endl;
      cin>>roll_no;
    }
   void show()
   {
     cout<<"Name : "<<name<<" Roll number: "<<roll_no<<endl;
   }
};

int main()
{
  person *p;
  p=new student;
  p->get_info();
  p->show();
  return 0;
}

4.8
5
Jlars62 110 points

                                    struct Abstract {
    virtual void f() = 0; // pure virtual
}; // &quot;Abstract&quot; is abstract
&nbsp;
struct Concrete : Abstract {
    void f() override {} // non-pure virtual
    virtual void g();     // non-pure virtual
}; // &quot;Concrete&quot; is non-abstract
&nbsp;
struct Abstract2 : Concrete {
    void g() override = 0; // pure virtual overrider
}; // &quot;Abstract2&quot; is abstract
&nbsp;
int main()
{
    // Abstract a; // Error: abstract class
    Concrete b; // OK
    Abstract&amp; a = b; // OK to reference abstract base
    a.f(); // virtual dispatch to Concrete::f()
    // Abstract2 a2; // Error: abstract class (final overrider of g() is pure)
}

4.8 (5 Votes)
0
4
8

                                    struct Abstract
{
     virtual ~Abstract() = 0;
};

Abstract::~Abstract() {}

struct Valid: public Abstract
{
        // Notice you don't need to actually overide the base
        // classes pure virtual method as it has a default
};


int main()
{
    // Abstract        a;  // This line fails to compile as Abstract is abstract
    Valid           v;  // This compiles fine.
}

4 (8 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
is abstract class example of abstraction in c++ why abstract class is used in c++ static and abstract class in c++ properties of abstract class in c++ can an abstract class have a constructor c++ abstract class and interface cpp can you have a variable of type abstract class c++ subclass of abstract c++ abstract class i cpp abstract class and interface in c++ cpp use an abstract class in a function c++ create instance of abstract class c++ derive from abstract class c++ reference to abstract class abstract class in c++ with example define abstract void cpp c++ class containing abstract class c++ class abstract c++ abstract method example c++ abstract class can implement constructor c++ abstract constructor call abstract class constructor c++ reference in c++ abstract class can have write a program to demonstrate the example of abstract class c++ abstract class and interfcae in cpp how to write function in an abstract class that have to be implemented c++ Why do we abstract class in c++ cpp inherit abstract class what is the application use of abstract class in c++ Can we have Constructor in Abstract class in cpp role of abstract class in c++ abstract class prototype cpp c++ creating an abstract class abstract class method c++ write importance of abstract class in c++ what is an abstract class?write down the advantage of using an abstract class with the necessary example in c++ need of abstract class in c++ abstract in c++ class abstract class in c++ javatpoint class abstract c+ set class abstract c++ abstract class in c++ definition abstract method in cpp c++ pure abstract class abstract functions cpp abstract template class c++ c++ assign abstract class why do we need abstract class in c++ cpp abstract include abstract methof c++ how to make abstract class in c++ abstract in c++ programming characteristics of abstract class in c++ abstract in c++; c++ uml abstract class abstract methods and classes in c++ benefits of abstract class in c++ class abstract c++ abstract class c+ how to make an abstract class in c++ What is an abstract type in C++? c++ when is a class abstract abstract class in C + + is created by c++ abstract class member examples of abstract class in c++ allocate abstract class c++ how to initialize abstract class c++ make abstract class c++ c++ abstract class tutorial what abstract in c++ urpose of abstract class c++ abstract level class c++ how to make abstract class C++ instances of C++ abstract classes how to implement abstract class method in c++ how to implement abstract method in c++ implementing abstract methods c++ using abstract classes c++ how to make an abstract class inc ++ abstract in cpp cpp abstract class nameing convetion abstract methods in c++ what is pure abstract class in c++ abstract class in ]c++ abstract class as type c++ abstract structure c++ what is abstract class c++ abstract class in c++ importance c++ function abstract expression abstract class in c++ abstract function in c++ abstract classesmn in c++ create object of abstract class c++ cpp abstract class example abstract function cpp abstract class in c++ sample code c++ abstract methods c++ when to use abstract class how to declare abstract class in c++ cpp inhereting abstract class c++ abstract class object c++ abstract class usage abstract class constructor c++ use abstract class to call function c++ use the abstract class c++ does an abstract class need a cpp file . Write a example program of abstract class in c++ How can we make a class abstract? c++ How to turn a class into an abstract class C++ what is abstract class in c+++ should abstract class metjods have defiitions C++ generic abstract class cpp class that holds abstract class c++ abstract class inc++ Which of the following is true of Abstract classes in c++: abstract keyword in c++ Which of the following is true of Abstract classes in c++ abstract class definition in c++ what happens if we don't define the function in an abstract class in c++ what happens if we donot define the function in an abstract class in c++ IS ABSTRACT CLASS AN INTERFACE IN C++ abstract keyword c++ abstract cpp abstract class syntax c++ how does abstract class work in c++ what makes a c++ class an abstract base class what is an abstract method in c++ what is abstract in c++ c++ abstract class constructor c++ abstract class method c++ make class abstract how do we declare an abstract class in c++ c++ why my class is abstract using abstract classes for objects c++ how to use constructor of abstract class c++ how to make a class abstract c++ making abstract function in class in c++ abstract c++ class example create object from abstract class c++ create abstract class example in c++ how to create abstract class in c++ implement an abstract class c++ can you define abstract class method c++ abstract c++ classes examples c++ abstract class declaration pure abstract class c++ what makes a class abstract in c++ interface and abstract class cpp use of having abstract class in c++ what it means that a class is abstract in c++ abstract classes in cpp c++ define member of an abstract class example of abstract class in c++ rules of abstract class c++ abstract clss c++ c++ is an abstract class can we create a constructor for abstract class in c++ can we create a constructor for abstract class c++ c++abstract class abstract method in c++ cpp abstract calss Which of the following statements creates an abstract class in C++? * abstract methods c++ why and when should we use an abstract class in c++ with example why and when should we use an abstract class in c++ do we have abstract classes in c++ cpp abstract define abstract class c++ interface and abstract class c++ use abstract class in c++ c++ abstract What are abstract classes? c++ creating an abstract class in c++ when to use abstract class and normal class in c++ can we create object of abstract class in c++ c++ abstract class in struct abstract class function cpp abstract functions in cpp c++ abstract class keyword how to extend abstract class C++ c++ implementing abstract class abstract class and interface in cpp write a program to illustrate abstract class in c++ why use abstract class in c++ c++ abstract code from method c++ abstract method properties of abstract classes in c++ virtual class cpure ++ cpp abstract classes cast to abstract class c++ how to make an abstract function in c++ c++ how to make abstract class abstract class and method in c++ real world abstract classes and virtual functions What does abstract mean c++ abstract class keyword c++ abstract class vs interface in c++ can abstract class have constructor c++ c++ abstract base class example c++ abstract class example abstact class c++ c++ interface vs abstract class c++ declare abstract class abstract class virtual function abstract keyword in c++ why use abstract keyword in cpp get data from abstract class c++ pure virtual function c++ abstract class cpp make class abstract how to declare an abstract class in c++ abstract static method c++ c++ abstract classes cpp abstract class In C++, abstract class can contain c++ make abstract class and select which functions to override in subclass virtual abstract class c++ abstract class defintion example c++ abstract claass c++ abstract class c__ c++ abstract method equals 0 c++ abstract class function c++ abstract class. c++ pure virtual function pure virtual examples abstract class car&quot; c++ pute virtual c++ What is an abstract class in C++? abstract c++ class pure virtual example how to create an abstract class in c++ c++ what is an abstract class pure virtual function in c++ syntax what is an abstract base class c++ c++ abstract class pointer type identifier Syntax for Pure Virtual Function is what are pure virtual function in c++ in which of the following classes is the abstract class used? in c++ in which of the following classes is the abstract class used what is the need of pure virtual functions in c++ by virtual function acheive abstraction in c++ make abstract class in c++ c++ abstract functions abstract class in c++ example c++ implements abstract class an abstract class needs pure virtual method? explain use of abstract class in c++ In C++, if any class has function, then that class is known as abstract class how to implement an abstract class in c++ how to implement abstract class in c++ abstract c++ a pure abstract class have all its method as final a pure abstract class have all its method as c++ function = 0; When do we make abstract class? Explain in detail. in cpp pure abstract class in c++ what is abstract class in c++ with example pure virtual function in c++ write a program to demonstrate the use of abstract class in c++ pure virtual function pure abstract class in cpp What is abstract class and pure abstract class? what is a abstract class in c++ abstract class in c++\ how can we make a class abstract in c++ Abstract class example in cpp all function in abstract class must be declarwed pure virtual what is the purpose of abstract class in c++ quora what are abstract classes cpp abstract class c++ example what is the purpose of abstract class in c++ abstract method c++ abstract base class c++ c++ make abstract class what are abstract classes in c++ c++ abstract function how do you implement abstract classes in c++ abstract class vs interface c virtural functions abstract class example c++ abstract class in c++ gfg what is an abstract class in c++ can we create object of abstract class c++ abstract class cpp c++ abstract class can contain in c++ abstract class can have both pure virual funtion in c++ abstract class can have only pure virual funtion in c++ abstract class can have construct an abstract class in C++ Construct an abstract class cpp abstract classes cpp What is the role of abstract class in c+ What is the role of abstract class in c++ how can we create an abstract class in c++ use a abstrac int method in c++ abstract class syntax in c++ abstract class in cpp use of abstract class in c++ use abstract class methods c++ how to make a class not abstract c++ what is an abstract class c++ abstract type variable in c++ abstract class in cpp gfg abstract calss in c++ how to make class abstract in c++ classes with only pure virtual function are used as which class in c++ virtual concrete interface or pure how to initialize an abstract class in c++ abstract class c++ abstract in c++ abstract classes c++ abstract classes in c++ interface in c++ gfg abstract class in c abstract function c++ c++ abstract class abstract class c abstract class in c++ what is abstract class in c++
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source