devxlogo

Classes and Structs — What’s the Difference?

Classes and Structs — What’s the Difference?

The keywords struct and class are almost interchangeable in C++. You can declare a struct that has member functions, constructors, destructor, base classes and so on as if it were a class. Likewise, it’s possible to create a class that has only public data members. The only difference between a struct and a class is in the default access. By default, all the members of a struct are public whereas in a class, al the members are private. The same is true for the default inheritance type: a struct entails public inheritance by default whereas a class entails private inheritance. The struct keyword struct exists for the sake of backward compatibility with C.

See also  How College Students Can Shape the Future of Tech Responsibility
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist