Talk:New coding guidelines: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(For further discussions about the guidelines)
 
(→‎auto vs auto*: new section)
Line 1: Line 1:
== <code>auto</code> vs <code>auto*</code> ==


When you use <code>static_cast</code>, wouldn't it be better to use <code>auto</code> instead of <code>auto*</code>?
<syntaxhighlight language="c++">
auto* obj = static_cast<Class*>(object);
// vs
auto obj = static_cast<Class*>(object);
</syntaxhighlight>
It would have the same result. Yes, <code>*</code> marks the variable as a pointer but
from the cast we can see that it is a pointer nonetheless.
-- [[User:Tracer|Tracer]] ([[User talk:Tracer|talk]]) 18:57, 25 June 2024 (UTC)

Revision as of 18:57, 25 June 2024

auto vs auto*

When you use static_cast, wouldn't it be better to use auto instead of auto*?

auto* obj = static_cast<Class*>(object);
// vs
auto obj = static_cast<Class*>(object);

It would have the same result. Yes, * marks the variable as a pointer but from the cast we can see that it is a pointer nonetheless.

-- Tracer (talk) 18:57, 25 June 2024 (UTC)