eldeshの日記: C++, 限定子としての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++がツン期に入ったようなのであとで調べよう….
C++, 限定子としてのtemplateの利用 More ログイン