C++, why is forward declaration not required in structs/classes

后端 未结 1 1473
醉话见心
醉话见心 2021-01-24 09:30

In C++, why does the following compile:

struct test {
    void foo() { this->bar++; }
    int bar;
};

But not the following:



        
相关标签:
1条回答
  • 2021-01-24 10:35

    In case of a structure, scope of the member variable is available within the structure. So if you define a function within a structure that variable will be available within the function.

    But that is the not the case in second scenario.

    0 讨论(0)
提交回复
热议问题