次のコードは合法ですか? MSVC 9とg ++ 4.4は反対する:しないg ++の間派生型は、そのベースのネストされた型と同じ名前にできますか?
c:\dev>cl test.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
test.cpp
test.cpp(10) : error C2146: syntax error : missing ';' before identifier 'type'
test.cpp(10) : error C2761: '{ctor}' : member function redeclaration not allowed
test.cpp(10) : error C2065: 'type' : undeclared identifier
:
struct base
{
struct derived {};
};
struct derived : base {};
int main()
{
typedef derived::derived type;
return 0;
}
MSVCは、型のコンストラクタのためのネストされた名前を混乱させ、不平を言う状況については
$ g++ --version test.cpp
g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
、私のコードpointer
というイテレータが含まれています。イテレーター・インターフェースを提供するために、ネストされたタイプpointer
を提供します。これは、それ自体の同義語です。
でエラーなしでコンパイルそれについて。 –
'typedef typename derived :: derived type;'で試してみて、それがうまく動作するかどうか確認してください。 –
申し訳ありませんが、私はあなたのコードを誤解しました。ちなみに、Comeauのコードは違法です( 'typename'の有無にかかわらず)、VC++がここにあると思う傾向があります。 –