Why doesn't the order of methods in a class matter in C++?

前端 未结 3 455
误落风尘
误落风尘 2021-01-21 06:11

I have been programming in C++ for quite some time and I never thought about this until today.

Consider the following code:

struct foo
{
  // compiles fi         


        
3条回答
  •  清歌不尽
    2021-01-21 06:50

    Compiler just starts to go down in a block. Any symbol which is not familiar to it will be considered as a new symbol which is not defined. This is the scheme behind the function definition or header files.

    You can suppose that the compiler first makes a list of definitions so the bar() method should get compiled correctly because the definitions have provided before.

提交回复
热议问题