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

前端 未结 3 450
误落风尘
误落风尘 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:49

    It has a lot to do with visibility. I think your confusion may come from assuming a single pass. Think of class parsing as done in two stages.

    1. Parse class definition.
    2. Parse method implementation.

    The advantage to this is we have visibility of the entire class from within class member functions.

提交回复
热议问题