devxlogo

Difference between structures & classes

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).

See also  Essential Measures for Safeguarding Your Digital Data
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