Constant of C++ member variables

Asked 2 years ago, Updated 2 years ago, 21 views

class Test
{
 constant temp = 1000; // The above behavior is said to be impossible in hot blood C++.
};

It worked well in VS2017 standards. Is the standard changed because the book of the hot blood is old? Or is it because the VS2017 compiler applied on its own?

The method of constant numbering of member variables through search is as follows using the member initializer.

class Test
{
    const int temp;
    Test() : temp(1000) {}
};

Even if it's the former, is it right to take the latter?

c++

2022-09-21 18:50

1 Answers

class Test
{
     constant temp = 1000; // The above behavior is said to be impossible in hot blood C++.
};

The above initialization is the method available in C++11. (Refer to the warning below)

VS2017 supports C++11, so it is thought to be compiled normally.

(Reference) https://docs.microsoft.com/ko-kr/cpp/what-s-new-for-visual-cpp-in-visual-studio?view=vs-2017

In this release, the C++ Compiler and Standard Library have been updated with enhanced support for C++11 and C++14 features and temporary support for specific features expected to be introduced in the C++17 standard.


2022-09-21 18:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.