Are valid resource access specifiers in front of each member of a class in C ++

I am writing C ++ code

public class SomeClass 
{
private: 
   int m_CurrentStatus;
   int m_PreviouseStatus;
public:
   int get_CurrentStatus() { return m_CurrentStatus; }
   int get_PreviouseStatus() { return m_PreviouseStatus; }
}

in C # style

public class SomeClass 
{
private:  int m_CurrentStatus;
private:  int m_PreviouseStatus;
public:   int get_CurrentStatus() { return m_CurrentStatus; }
public:   int get_PreviouseStatus() { return m_PreviouseStatus; }
}

Are such access-use qualifiers in front of each class member acceptable? Or may there be a problem with the compiler spending more time compiling or other effects? Code successfully compiled without warning.

+4
source share
5 answers

What you are describing is legal C ++.

The effect on compilation time will depend on the compiler. However, in practice, it will probably be difficult for you to find any difference in compilation time.

. - , . , "" (, (public, private protected)) , (, ). , , , . - . , , , - , .. ..

. ++ , -. , ( ) ( , ..), . . , (), , , .

+3

, , . , .

+1

++,
public class
(;) .

- , , , , , , , (, ).

+1

, , , . 50 . ++.

+1

, . - , , . - .

The only thing that may interfere with the compiler in your case (depending on the time) is that your function block is inside the class.

What I mean?

If you have main.cpp and class.h, and your functions are declared and defined inside the .h class, your compilation will take a little longer, and not if your function body is in functions.cpp

+1
source

Source: https://habr.com/ru/post/1667876/


All Articles