devxlogo

Difference between structures & classes

Question:
Why use classes when the same can be implemented using structures?

Answer:
Reasonable question. For starters, structures in C could not work like classes. Classes were needed to implement object-oriented programming. Then it looks like the designers of C++ decided they might as way give the class functionality to structures as well (which are similiar to classes).

I don’t know all the thinking that went into that, but the two are very similar. The primary difference is that, by default, structure members are public (can be accessed by code that references the structure), while class members are private (which is more in line with the OOP approach).

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Five Early Architecture Decisions That Quietly Get Expensive

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.