using declarationは、宣言されている場所から見える名前しか、宣言場所のスコープに導入しない。
namespace NS { void f( int ) { } }
// NS::f(int)をグローバル名前空間に導入する
// NS::f(double)は、ここでは、まだ宣言されていない
using NS::f ;
namespace NS { void f( double ) { } }
int main()
{
// NS::f(int)を呼ぶ
// NS::f(double)という名前は、この場所からは名前探索されない。
f( 0.0 ) ;
// NS::f(double)をmain関数のブロックスコープに導入する
using NS::f ;
// ここでは、NS::f(double)が名前探索できる
// オーバーロード解決により、NS::f(double)を呼ぶ
f( 0.0 ) ;
}
宣言なしに名前を使うことはできないというのは、C++の原則である。しかし、これはなかなか面白い仕様だ。
No comments:
Post a Comment
You can use some HTML elements, such as <b>, <i>, <a>, also, some characters need to be entity referenced such as <, > and & Your comment may need to be confirmed by blog author. Your comment will be published under GFDL 1.3 or later license with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.