パスワードを忘れた? アカウント作成
51555 journal

eldeshの日記: C++, 限定子としてのtemplateの利用

日記 by eldesh
VC++のフィードバック に限定子としてのtemplateの使用で依存名解決(?)な話があるので,
以下のコードを書いてみた.

#include <iostream>

template< typename T >
class Depend {
    T x_;
public:
    Depend( T x ) : x_(x) {}

    template< typename U >
    void print( const U & x ) const {
        std::cout << "T:" << x_ << "\n"
            <<   "U:" << x  << std::endl;
    }
};

template< typename T >
void test( const T & t ) {
                                                // コンパイルが通ったコンパイラ
    t.template print(20.2839);              // g++ 4.1.2, VC++2005
    t.print(20.2839);                       // g++ 4.1.2
    t.template print<double>(20.2839);      // g++ 4.1.2
}

int main(){
    Depend<int> dep(5);
    test(dep);
    return 0;
}

C++では,テンプレートパラメータに依存する名前がメンバテンプレートである場合には, キーワード'template'でコンパイラに教えてあげないと メンバ変数と見分けがつかない.

と,理解したんだけど…
あれ?VCは規格通りの動作に見えるよ?
むしろgccが…(汗

C++がツン期に入ったようなのであとで調べよう….

この議論は賞味期限が切れたので、アーカイブ化されています。 新たにコメントを付けることはできません。
typodupeerror

物事のやり方は一つではない -- Perlな人

読み込み中...