C++11から、次のように書くことができます
#include <vector>
#include <string>
struct S
{
S(int x, const std::string& s)
: x(x)
, s(s)
{
}
int x;
std::string s;
};
// ...
std::vector<S> v;
// add new object to the vector v
// only parameters of added object's constructor are passed to the function
v.emplace_back(1, "t");
emplace
またはemplace_back
コンテナー クラス ( ) のような C++ 関数の C# 類似物はありますSystem.Collections.Generic.List
か?
更新:
C# では、同様のコードがlist.EmplaceBack(1, "t");
の代わりにとして記述される場合がありlist.Add(new S(1, "t"));
ます。クラス名を覚えなくて、new ClassName
毎回こういうシチュエーションで書いてくれるといいですね。