最近、protoype を書くための本当に奇妙な方法に直面しています:
void myProto( QList<::myObject::myStruct> myStructList );
そして、「<::」と「>」の意味を知りたいですか?
ありがとう !
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.
::myObject::myStruct
グローバルスコープにあるmyStruct
クラス(または名前空間)で定義された参照を意味します。myObject
<>
型はこれらの括弧内に入り、その型のテンプレートの特殊化を示します。
次のプログラムをコンパイルします
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
です。