2

最近、protoype を書くための本当に奇妙な方法に直面しています:

void myProto( QList<::myObject::myStruct> myStructList );

そして、「<::」と「>」の意味を知りたいですか?

ありがとう !

4

3 に答える 3

8

QList is a template, and QList<Type> is a specialization of that template, with the actual type ::myObject::myStruct.

The :: is the scope resolution operator, which tells the compiler to look for myStruct in the scope of myObject, which itself is at global scope.

于 2013-02-27T14:50:11.210 に答える
4
::myObject::myStruct

グローバルスコープにあるmyStructクラス(または名前空間)で定義された参照を意味します。myObject

<>

はこれらの括弧内に入り、その型のテンプレートの特殊化を示します

于 2013-02-27T14:49:51.823 に答える
0

次のプログラムをコンパイルします

struct A // GLOBAL A
{
    void f()
    { }
};

namespace nm
{
    struct A // nm::A
    { };

    template <class T>
    struct B
    {
        T a;

    };

    void f1(B<A> b) // WILL NOT COMPILE
    {
        b.a.f();
    }

    void f2(B< ::A> b)  // WILL COMPILE
    {
        b.a.f();
    }
}

int main()
{

}

nm::f1コンパイルされません

nm::f2コンパイルします

これは、::A(グローバル A) にはfメンバーがあり 、メンバーnm::Aがないためfです。

于 2013-02-27T14:58:08.223 に答える