<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    weidagang2046的專欄

    物格而后知致
    隨筆 - 8, 文章 - 409, 評論 - 101, 引用 - 0
    數據加載中……

    using Declaration

    Syntax

    using [typename][::] nested-name-specifier unqualified-id
    using :: unqualified-id

    The using declaration introduces a name into the declarative region in which the using declaration appears. The name becomes a synonym for an entity declared elsewhere. It allows an individual name from a specific namespace to be used without explicit qualification. This is in contrast to the using directive, which allows all the names in a namespace to be used without qualification. See using Directive for more information.

    A using-declaration can be used in a class definition. For example:

    class B
    {
        void f(char);
        void g(char);
    };
    
    class D : B
    {
        using B::f;
        void f(int) { f('c'); }        // calls B::f(char)
        void g(int) { g('c'); }        // recursively calls D::g(int)
                                       // only B::f is being used
    };
    

    When used to declare a member, a using-declaration must refer to a member of a base class. For example:

    class C
    {
        int g();
    };
    
    class D2 : public B
    {
        using B::f;          // ok: B is a base of D2
        using C::g;          // error: C isn't a base of D2
    };
    

    Members declared with a using-declaration can be referenced using explicit qualification. The :: prefix refers to the global namespace. For example:

    void f();
    
    namespace A
    {
        void g();
    }
    
    namespace X
    {
        using ::f;        // global f
        using A::g;       // A's g
    }
    
    void h()
    {
        X::f();           // calls ::f
        X::g();           // calls A::g
    }
    

    Just as with any declaration, a using-declaration can be used repeatedly only where multiple declarations are allowed. For example:

    namespace A
    {
        int i;
    }
    
    void f()
    {
        using A::i;
        using A::i;        // ok: double declaration
    }
    
    class B
    {
    protected:
        int i;
    };
    
    class X : public B
    {
    public:
        using B::i;
        using B::i;        // error: class members cannot be multiply declared
    };
    

    When a using-declaration is made, the synonym created by the declaration refers only to definitions that are valid at the point of the using-declaration. Definitions added to a namespace after the using-declaration are not valid synonyms. For example:

    namespace A
    {
        void f(int);
    }
    
    using A::f;        // f is a synonym for A::f(int) only
    
    namespace A
    {
        void f(char);
    }
    
    void f()
    {
        f('a');            // refers to A::f(int), even though A::f(char) exists
    }
    
    void b()
    {
        using A::f;        // refers to A::f(int) AND A::f(char)
        f('a');            // calls A::f(char);
    }
    

    A name defined by a using-declaration is an alias for its original name. It does not affect the type, linkage or other attributes of the original declaration.

    If a set of local declarations and using-declarations for a single name are given in a declarative region, they must all refer to the same entity, or they must all refer to functions. For example:

    namespace B
    {
        int i;
        void f(int);
        void f(double);
    }
    
    void g()
    {
        int i;
        using B::i;          // error: i declared twice
        void f(char);
        using B::f;          // ok: each f is a function
    }
    

    In the example above, the using B::i statement causes a second int i to be declared in the g() function. The using B::f statement does not conflict with the f(char) function because the function names introduced by B::f have different parameter types.

    A local function declaration cannot have the same name and type as a function introduced by a using-declaration. For example:

    namespace B
    {
        void f(int);
        void f(double);
    }
    
    namespace C
    {
        void f(int);
        void f(double);
        void f(char);
    }
    
    void h()
    {
        using B::f;          // introduces B::f(int) and B::f(double)
        using C::f;          // C::f(int), C::f(double), and C::f(char)
        f('h');              // calls C::f(char)
        f(1);                // error: ambiguous: B::f(int) or C::f(int)?
        void f(int);         // error: conflicts with B::f(int) and C::f(int)
    }
    

    When a using-declaration introduces a name from a base class into a derived class scope, member functions in the derived class override virtual member functions with the same name and argument types in the base class. For example:

    struct B
    {
        virtual void f(int);
        virtual void f(char);
        void g(int);
        void h(int);
    };
    
    struct D : B
    {
        using B::f;
        void f(int);         // ok: D::f(int) overrides B::f(int)
    
        using B::g;
        void g(char);        // ok: there is no B::g(char)
    
        using B::h;
        void h(int);         // error: D::h(int) conflicts with B::h(int)
                             // B::h(int) is not virtual
    };
    
    void f(D* pd)
    {
        pd->f(1);            // calls D::f(int)
        pd->f('a');          // calls B::f(char)
        pd->g(1);            // calls B::g(int)
        pd->g('a');          // calls D::g(char)
    }
    

    All instances of a name mentioned in a using-declaration must be accessible. In particular, if a derived class uses a using-declaration to access a member of a base class, the member name must be accessible. If the name is that of an overloaded member function, then all functions named must be accessible. For example:

    class A
    {
    private:
        void f(char);
    public:
        void f(int);
    protected:
        void g();
    };
    
    class B : public A
    {
        using A::f;          // error: A::f(char) is inaccessible
    public:
        using A::g;          // B::g is a public synonym for A::g
    };
    

    from: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/tions_43.asp

    posted on 2006-03-12 13:44 weidagang2046 閱讀(797) 評論(0)  編輯  收藏 所屬分類: C/C++

    主站蜘蛛池模板: 精品四虎免费观看国产高清午夜| 亚洲av中文无码乱人伦在线r▽| 亚洲免费观看在线视频| 无码少妇精品一区二区免费动态| 亚洲精品你懂的在线观看| 中文在线观看永久免费| 国产成人精品日本亚洲网站 | 亚洲成色www久久网站夜月| 97无码人妻福利免费公开在线视频| 亚洲无人区午夜福利码高清完整版| 精品一区二区三区免费观看 | 华人在线精品免费观看| 亚洲精品卡2卡3卡4卡5卡区| 中文字幕免费在线视频| 亚洲午夜精品一区二区| 91成年人免费视频| 亚洲丁香婷婷综合久久| 亚洲精品国产电影| 久久成人免费电影| 国产v亚洲v天堂a无| 国产精品国产自线拍免费软件| 美国毛片亚洲社区在线观看 | 亚洲一区二区三区写真 | 男男AV纯肉无码免费播放无码| 亚洲日韩一区精品射精| 全黄a免费一级毛片人人爱| 免费在线黄色电影| 亚洲精品福利你懂| 亚洲精品无码AV中文字幕电影网站| 成人A片产无码免费视频在线观看| 亚洲黄网在线观看| 国产裸模视频免费区无码| 国产黄片不卡免费| 亚洲大尺码专区影院| 国产免费人视频在线观看免费 | 亚洲国产精品无码久久九九大片| 亚洲美日韩Av中文字幕无码久久久妻妇| 成人久久免费网站| 亚洲欧美日韩中文字幕一区二区三区| 伊人久久大香线蕉亚洲五月天 | 97人妻无码一区二区精品免费|