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.
次のクラスがあるとします。
class MyRecord { public: int a; int b; MyRecord() : MyRecord(8, 9) {}; MyRecord(int a, int b) : a(a), b(b) {}; };
ベクトルを初期化する最も簡単な方法は何 std::vector<MyRecord> myVectorですか?データを使用しますか?
std::vector<MyRecord> myVector
例を介して実証:
MyRecord exampleRecord(3,4); std::vector<MyRecord> myVector = {{1,2}, {}, exampleRecord};
検証のために、次のコード
for (MyRecord &record : myVector) { std::cout << "a:" << record.a << " b:" << record.b << std::endl; }
出力します:
a:1 b:2 a:8 b:9 a:3 b:4