ADVERTISEMENT
ADVERTISEMENT

Home » C++ programs

C++ | Create an empty class (a class without data members and member functions)

Here, we are going to learn how to create an empty class (a class without data members and member functions) in C++ programming language?
Submitted by IncludeHelp, on March 01, 2020

In the below program, we are creating a C++ program to create an empty class (a class without data members and member functions).

#include <iostream>

using namespace std;

// class definition
class Person {};

// main function
int main() {
  //object creation
  Person per;
  
  // here - we are printing size of the object
  cout << "size of per: " << sizeof(per) << endl;
  
  return 0;
}

Output

size of per: 1

See the program – here class named Person doesn't have any data member and member function – it will be known as an empty class.

ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.