Why is no qualification necessary?

后端 未结 4 637
梦如初夏
梦如初夏 2021-02-13 12:22

OK, I\'ll just post the complete program even though it has extraneous stuff and the code in question is the dead code…

#include 
#include         


        
4条回答
  •  逝去的感伤
    2021-02-13 12:59

    Another observation is that ios_base::openmode works, but ios::openmode does not:

    class InFStream
        : public std::ifstream
    {
        // ...
        ios::openmode m1;       // error: ios does not name a type
        ios_base::openmode m2;  // ok
    }
    

    I think a1ex07 has found the crux of the matter: here again, ios_base is the name of a class, while ios is merely a typedef.

    And the difference is that the name of a class is a member of that class (9/2), and so can be looked up as the name of the type in InFStream (3.4.1/7 item 1) as it is a member of a base class of InFStream. But some typedef merely alongside the base class off in some other namespace can't be seen.

    [Standard section numbers from C++98.]

提交回复
热议问题