私が定数値を持っているとしましょう(おそらくいくつかの列挙型)。私は多くのクラスA、B、Dなどを持っているとしましょう.
私はこのようなものを持つことができますか?
C<1> anInstanceOfA; //This will be of type A
C<2> anInstanceOfB; //This will be of type B
C<3> anInstanceOfD; //This will be of type D
では、コンパイル時に定数に基づいてクラスを選択することは可能ですか?
一般的な問題は、インデックスが列挙型であるテーブルに基づいてファンクターを選択しようとしていることです。できればポリモーフィズムは避けたいです。
編集:このプロジェクトでは、C++ 11 を使用できません。とにかく、そのコンテキストで回答した人に感謝します。とにかく知るのは非常に興味深いです。
編集 2:一般に、2 つ以上のターゲット クラスを持つことができます。質問を編集しました。