What are the differences between struct and class in C

0 votes
I now want to understand the distinctions between a C++ class and struct.

Please go through the technical distinctions and the justifications for selecting one over the other in OO design.

I'll start with a clear distinction:

A struct's members are public by default if you don't specify public: or private:, but a class's members are private by default.

In the tucked-away areas of the C++ standard, I'm sure there are other variances.
Aug 17, 2022 in C++ by Nicholas
• 7,760 points
631 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
You overlook the complex second distinction between classes and structs.

According to the specification (11.2.2 for C++98 through C++11):

When a derived class is declared as a struct (without an access-specifier), public is presumed, whereas when a class is specified as a class, private is assumed.

And just to be thorough, (11.2) defines the more well-known distinction between class and struct as follows:

By default, members of a class specified with the term class are private.

The default access level for members of a class declared with the keywords struct or union is public.

Another distinction is that the keyword class can be used to declare template arguments, whereas the keyword struct cannot.
answered Aug 23, 2022 by Damon
• 4,960 points

edited Mar 5

Related Questions In C++

0 votes
1 answer

What is the difference between public, private, and protected inheritance in C++?

To begin answering that question, let me characterise member accessors in my own terms.  If you already know this, proceed to the section "next:". I'm aware of three types of accessors: public, protected, and private. Let: class Base { public: ...READ MORE

answered Jul 11, 2022 in C++ by Damon
• 4,960 points
862 views
0 votes
0 answers

What are the differences between a pointer variable and a reference variable?

What distinguishes a reference variable from a ...READ MORE

Jul 11, 2022 in C++ by Nicholas
• 7,760 points
593 views
0 votes
1 answer

What is the difference between operator overloading and operator overriding in C++?

Some people use the latter word to ...READ MORE

answered Aug 2, 2022 in C++ by Damon
• 4,960 points
2,088 views
0 votes
0 answers

What is the difference between std::list<std::pair> and std::map in C++ STL?

What distinguishes std::list<std::pair> from std::map? Does the ...READ MORE

Aug 17, 2022 in C++ by Nicholas
• 7,760 points
862 views
0 votes
1 answer

C++ code file extension? What is the difference between .cc and .cpp [closed]

GNU GCC recognizes all of the following ...READ MORE

answered Jun 21, 2022 in C++ by Damon
• 4,960 points
1,712 views
0 votes
1 answer

What is a Class and Object in C++?

A Class is like a blueprint, an ...READ MORE

answered Jun 21, 2022 in C++ by Damon
• 4,960 points
613 views
0 votes
0 answers

What is the difference between a concrete class and an abstract class?

I'm learning C++, but I'm having trouble ...READ MORE

Jul 26, 2022 in C++ by Nicholas
• 7,760 points
576 views
0 votes
1 answer

What is the purpose of inner class in Python?

Advantages of inner class: Logical grouping of classes: ...READ MORE

answered Feb 7, 2019 in Python by SDeb
• 13,300 points
2,435 views
0 votes
1 answer

What's the difference between struct and class in .NET?

In .NET, there are two categories of ...READ MORE

answered Feb 8, 2022 in Others by Soham
• 9,710 points
517 views
0 votes
0 answers

Is hiding implementation detail Encapsulation or Abstraction?

I have seen some people defining abstraction ...READ MORE

May 6, 2022 in Java by narikkadan
• 63,600 points
3,532 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP