Class vs Struct

Hi. Just curious about the difference between classes and structures. I know that class members are default private and struct members are default public. Is there any difference beyond that?

Also, is there a situation where its best to use one or the other? Or are they synonymous if you are explicit with the encapsulation?
There is no difference beyond what you stated. Generally, structs are used when you only have data, while classes are used when you want additional functionality.
closed account (zb0S216C)
There's 1 small difference: base classes are public, too. Other than that, there's absolutely no difference between the two.

Owain wrote:
"Also, is there a situation where its best to use one or the other?"

Well, no. I consider the choice a personal preference. That being said, I use "struct" more as it more closely describes the implementation. For example: "struct array", or, "struct stack"; both are "struct"ures. I find that "class" is not as descriptive as "struct" in most cases.

Owain wrote:
"Or are they synonymous if you are explicit with the encapsulation?"

As you & I said, there's no difference between the two, other than the said differences.

Wazzak
Last edited on
Topic archived. No new replies allowed.