What is the difference between C unions and C++ unions? [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
What are some major differences between unions in C and C++?

In a nutshell, a C++ union can have constructors and destructors, and non-virtual functions. (Note that a C++ union cannot have a base class and cannot be a base class.)
Everything else is pretty much the same between C and C++.

Related

Can anyone tell me a practical situation from real-life applications where friend functions can be useful? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am a newbie in OOP (C++) and just learned about friend function but is there a real life example that defines the usage of friend function ?
I am developing a large class library where some of them provide services used by others, such as graphics.
I am not exposing the inner mechanisms to the normal users, but my classes and functions are allowed to. Hence, friends.

why a protected member is allowed in a C++ class marked as final? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
A similar question has been already asked in stackoverflow regarding Java.
But C++ does not behaves exactly as Java and, in particular, C++ does not allow access on protected members of a class "...from another package...".
So, what is the rational to allow protected members inside class marked as final ? Is a convenient way for the developer to quickly switch a class from final to non final (if the design change) ?

Encapsulation of structure in class [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Is it good practice to encapsulate a structure used by a class inside the class if only the class uses it and not the user who will end up using the class, or does it not matter?
It is generally poor practice to expose any internal details in the headers.
See GotW #100: Compilation Firewalls for more details.

Need for undefined behaviour in c and c++? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Is there is any specific reason behind undefined behavior in C and C++?
Why are some features left undefined?
For some part at least, it was to allow a more efficient implementation.
A simple example: Function parameters. Their evaluation order in unspecifed, because some architectures could work better depending on how they made the calculations or the calling convention (registers, stack, etc.)

Should all classes that aren't inherited be final? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Should I declare all classes that aren't inherited as final even if they don't have anything to do with inheritance and that kind of stuff?
A class should be declared final when you want to declare the statement "this class cannot be inherited". This is not the same case as the statement "this class is not inherited". It is a matter of opinion but I would not forbid the inheritance of a class, unless there is a very specific reason to do so. Therefore, I would not declare a class final unless there was a reason to do so.
Hope I helped!