Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
c ++でコードを記述して、パラメーターの数が不明なコンストラクターを使用してクラスを初期化できるようにします。クラスに配列があり、コンストラクターに渡して配列に格納するすべての値を格納したいと思います。そうすることは可能ですか?
C ++ 11での最善のアプローチは、配列に格納されている型std::initializer_list<T>がwhereである構造を使用することです。T
std::initializer_list<T>
T
他のオプションには、別の配列へのポインター、またはstd::vector<T>(BTW、std::vectorプレーン配列ではなく使用を検討してください)が含まれます。
std::vector<T>
std::vector