This question already has answers here:
Prevent class inheritance in C++
(9 answers)
Closed 6 years ago.
How to prevent your class from being inherited in c++?
How to prevent your class from being inherited in c++?
Mark it as final.
class MyData final {
// ...
};
Related
This question already has answers here:
What are the rules for calling the base class constructor?
(10 answers)
How do I call the base class constructor?
(6 answers)
Closed 11 months ago.
I found this C++ constructor that uses an initialization list I don't understand what this convention is. I do know this initialization list can be use to instantiate a member of a instance with a param, but I've never seen a class constructor called from a list.
// G inherits from H
class GBackend : public HBackend {...}
// Constructor for G
// What is this HBackend constructor doing?
GBackend::GBackend(const BackendOptions& options) : HBackend(options), g_options(options) {...}
This question already has answers here:
What are the differences between struct and class in C++?
(30 answers)
Closed 2 years ago.
When writing C++ code, what is the difference between using class and struct?
class Foo final { };
vs.
struct Bar final { };
When should I prefer one over the other? Is this merely a choice of programming/coding style?
A struct simply defines the layout of a piece of storage.
A class is a dynamically-allocated "thing" which can have methods ... it can do things.
This question already has answers here:
Detect if a default constructor exists at compile time [duplicate]
(2 answers)
Is there a way to test whether a C++ class has a default constructor (other than compiler-provided type traits)?
(8 answers)
Closed 3 years ago.
It is possible to check for a user defined constructor?
For example I have the following code
class A {};
class B {
public:
B(){/* do stuff */}
};
And I want to be able to do something like this:
printf("%d", check_for_user_default_constructor<B>::value);
printf("%d", check_for_user_default_constructor<A>::value);
and to have a true value only for class B.
This question already has answers here:
C++: How do I pass a container of derived classes to a function expecting a container of their base classes?
(4 answers)
C++: Can I cast a vector <derived_class> to a vector <base_class> during a function call?
(5 answers)
Closed 7 years ago.
I want to create a generic function which gets vector types as argument.
Derived1, Derived2, ... are derived (simply) from Base
I tried something like this:
int function (vector& foo)
It didn't work.
Could you tell me, what is the best generic solution for this problem?
This question already has answers here:
Is there any reason to use this->
(16 answers)
Use of "this" keyword in C++ [duplicate]
(6 answers)
Closed 8 years ago.
Class::Class() {
this->func();
}
and
Class::Class() {
func();
}
Are there any differences between these two ways of calling a function?
Yes, this->var ensures you're working with instance variable - which may be useful when your instance variables may be shadowed inside a block.