The effect of moving a method from public to private

I did code cleanup and started wondering about something specific.

Assuming I have a program that compiles, runs, and usually does what it should.

Now I am moving a specific class method from public to private (or protected), and the code still compiles without errors.
Is it theoretically possible to have a scenario in which the behavior of a program would change as a result of code changes?
If so, I would like to see an example.

+8
c ++
source share
2 answers

The method access specifier does not explicitly affect the search (it is checked after the search is completed), so I do not believe that in the absence of undefined behavior there may be hidden changes in functionality (for example, you are another version of the class where the function still remains open).

0
source share

Access control is checked after the search to make sure that you suggest not changing the behavior of the program. Just remember that reordering member variables, even private ones, can change behavior because they are arranged in the order in which they appear in the class declaration.

0
source share

All Articles