- 1 名前:デフォルトの名無しさん mailto:sage [04/11/25 21:11:32]
- C++ のジェネリックプログラミングの話をしましょう。
以下のスレッドを統合するスレです。 STLスレッド Part1 pc.2ch.net/tech/kako/1004/10042/1004287394.html Part2 pc3.2ch.net/tech/kako/1026/10267/1026793823.html 【C++】Boost使い集まれ! pc3.2ch.net/test/read.cgi/tech/1033830935/ (html化待ち?) Generic Programming with C++ Template pc.2ch.net/tech/kako/1008/10085/1008593126.html 【C++】template 統合スレ -- STL/Boost/Loki, etc. pc2.2ch.net/tech/kako/1037/10377/1037795348.html 【C++】template 統合スレ -- Part2 pc2.2ch.net/test/read.cgi/tech/1047978546/ (html化待ち) 【C++】template 統合スレ -- Part3 pc5.2ch.net/test/read.cgi/tech/1066493064/ (html化待ち) 【C++】template 統合スレ -- Part4 pc5.2ch.net/test/read.cgi/tech/1083550483/ (html化待ち) 【C++】template 統合スレ -- Part5 pc5.2ch.net/test/read.cgi/tech/1091522597/ 関連スレ、その他リンクは >>2-5 あたりに。
- 783 名前:デフォルトの名無しさん mailto:sage [2005/08/06(土) 02:36:31 ]
- 次のようなコードが、Visual C++では通るけどGCCでは通りません。
オブジェクトの名前と番号の型を保持する構造体を用意 template<class S,class I> struct Types { typedef S String; typedef I Integer; }; この定義を受け取って型を定義するベースクラスを作成 template<class T> struct Base { typedef typename T::String StringType; typedef typename T::Integer IntegerType; }; そして、これを利用するサブクラスを作成。 template<class T> struct Derived : public Base<T> { StringType name; //!< ここでコンパイルエラー IntegerType number; //!< 同様 }; typedef Types<std::string,int> StdTypes; Derived<StdTypes> derived;
- 784 名前:デフォルトの名無しさん mailto:sage [2005/08/06(土) 02:38:23 ]
- 続き
以下のように書けばGCCでもコンパイルは通ります。 typename Derived::StringType name; typename Derived::IntegerType number; こんな面倒な書き方しかできないなら、 わざわざベースクラスにtypedefした意味がないんですが 何かいい方法ありませんか?
|

|