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

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!

Related

What is the difference between C unions and C++ unions? [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
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++.

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

Formatting of 'this' pointers [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
To be honest (*this) looks a lot better than this->. They both function the same. Why shouldn't I use the former? Is it just common practice to use this->, or is there something more to it?
Actually both will have same results when accessing data-members. Though you find (*this) more elegant I would undoubtedly say most will disagree.

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.

Is it a good practice to omit parameter names in declarations? [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
With parameter names:
class Foo
{
public:
someType f(someType parameterName);
};
Without Parameter names:
class Foo
{
public:
someType f(someType);
};
In terms of C++, which one is recommended? Or just a personal preference?
I don't see any advantage in omitting the names from the declaration.
On the other hand, I do see several disadvantages:
Your code is less readable.
Your intention is less clear.
It gets a lot more messy to get the code to work ("wait a second, why does PowerOf2("10,2"); Gives me 1024? I was expecting 100.")