std::vector
単一の値を返す (仮想) 関数があります。クラスが次のようになっているとします。
#include <vector>
class Z; // irrelevant
class C
{
Z& something;
public:
typedef std::vector<Z*> list_type;
virtual list_type f();
};
反復コンストラクターを使用する方が良いですか:
C::list_type C::f()
{
return list_type(1, &something);
}
またはpush_back()
単一の要素のみ:
C::list_type C::f()
{
list_type ret;
ret.push_back(&something);
return ret;
}