why do we need parentheses for destructor definition? [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 6 years ago.
Improve this question
I know how to define destructor is just like this
~ClassName()
{
}
and destructor can't have parameter. then why we must write parentheses after the class name? since destructor can't have parameter and i think there is no benefit of it. or there is other function of it?
i think it will be better if there is no parantheses needed because it make clear destructor can't have parameter
~ClassName
{
}

Two reasons so far
It is a function so it needs the syntax declaration of a function.
Why is the function declaration syntax like that? It's how the grammar
was defined.

In the D programming language the parenthesis of functions are optional when there are no arguments. D is designed to be a better C++. You might be interested in that language https://dlang.org/

Related

Is there a reason I've never seen std::as_const as a way of differentiating between mutable and non-mutable parameters? [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 2 years ago.
Improve this question
One of the nicer features of Rust is explicitly showing whether parameters are mutable, non-mutable, or moved from the caller's site:
foobar(&mut foo, &bar, baz);
// ^ mutable ^ non-mutable ^ moved (copied if trivial)
In C++ we already have tools to do this:
foobar(std::ref(foo), std::as_const(bar), std::move(baz));
Yet, though std::move is standard practice, I've never seen std::as_const being used in a function call.
Is there a reason for this, other than maybe std::as_const is too verbose? Would adding simpler syntactic sugar for it provide a good new feature that makes C++ more readable?

Scopes in blank function c++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Hy, my question is simple..
I have this function.
CPythonMessenger::CPythonMessenger(): m_poMessengerHandler(NULL)
{
}
What scope have and why is there since constructor is empty and also is not used m_poMessengerHandler(NULL) i want to say the function is not used anywhere is constructor.
I guess you are examining (or maybe it is your code) THIS.
CPythonMessenger is the default constructor for the class CPythonMessenger as you can see in the relative header file HERE. After the : you can invoke a method (or another constructor) that must be run when creating an object of CPythonMessenger type. In particular, it creates an instance of m_poMessengerHandler that is then used in several place in the other class methods.

How operator overloading in C++ impacts on performance? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I was given a question: how operator overloading in C++ impacts on performance?
I'm not pretty sure how to answer it. I fully understand the idea and how to overload operators in C++, but what about performance?
Calling an overloaded operator is the same as calling any function in the object. If you mark the operator as inline, you get the same benefits (or lack thereof) as any other inline function.
Nothing complicated at all.

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

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!