MSVCRT std::vector 新しいページはコチラ
提供: yonewiki
(→メンバ関数 emplace_back) |
(→メンバ関数 emplace_back) |
||
79行: | 79行: | ||
*<span style = "background:linear-gradient(transparent 75%, #cab8d9 75%); font-weight:bold; "><span style="color:deeppink;">void</span> <span style="color:blue;">obj.emplace_back</span>(<span style="color:deeppink;">TypeTemplate(vector<TypeTemplate>&&...)</span>);</span> | *<span style = "background:linear-gradient(transparent 75%, #cab8d9 75%); font-weight:bold; "><span style="color:deeppink;">void</span> <span style="color:blue;">obj.emplace_back</span>(<span style="color:deeppink;">TypeTemplate(vector<TypeTemplate>&&...)</span>);</span> | ||
*<span style = "background:linear-gradient(transparent 75%, #cab8d9 75%); font-weight:bold; "><span style="color:deeppink;">TypeTemplate&(refference_InsertValue)</span> <span style="color:blue;">obj.emplace_back</span>(<span style="color:deeppink;">TypeTemplate(vector<TypeTemplate>&&...)</span>);</span> | *<span style = "background:linear-gradient(transparent 75%, #cab8d9 75%); font-weight:bold; "><span style="color:deeppink;">TypeTemplate&(refference_InsertValue)</span> <span style="color:blue;">obj.emplace_back</span>(<span style="color:deeppink;">TypeTemplate(vector<TypeTemplate>&&...)</span>);</span> | ||
+ | |||
+ | TypeTemplate(vector<TypeTemplate>)はvectorの型テンプレートで型を生成するコンストラクタによって初期化形式である必要があります。?何を言っているの? | ||
+ | |||
+ | 例えばvectorはvector<std::string> obj;のようにstd::string型を定義した場合。objはsdt::string型が順序を持って連続するような値になります。そうすると以下の例のように定義します。 | ||
+ | |||
+ | sample.cpp | ||
+ | <syntaxhighlight2 lang="cpp"> | ||
+ | #include<cstidio> | ||
+ | #include<vector> | ||
+ | |||
+ | int main(int iArgc char** cArgv){ | ||
+ | std::vector<std::string> objVectorStdString_data; | ||
+ | |||
+ | obj.emplase_back(std::string("Hello! VectorDataString!")); | ||
+ | //std::stringのコンストラクタでstd::string型そのものが右辺値参照として引数になる。 | ||
+ | } | ||
+ | </syntaxhighlight2> | ||
+ | |||
+ | ※C++17以降は2つ目に書いたように TypeTemplate& のような挿入したデータへの参照を返却され、受け取ることができます。 | ||
+ | |||
+ | |||
+ | |||
+ | === '''メンバ関数 push_back''' === | ||
+ | *<span style = "background:linear-gradient(transparent 75%, #cab8d9 75%); font-weight:bold; "><span style="color:deeppink;">void</span> <span style="color:blue;">obj.push_back</span>(<span style="color:deeppink;">const TypeTemplate&</span> type);</span> | ||
+ | *<span style = "background:linear-gradient(transparent 75%, #cab8d9 75%); font-weight:bold; "><span style="color:deeppink;">void</span> <span style="color:blue;">obj.push_back</span>(<span style="color:deeppink;">TypeTemplate&&</span> type);</span> | ||
TypeTemplate(vector<TypeTemplate>)はvectorの型テンプレートで型を生成するコンストラクタによって初期化形式である必要があります。?何を言っているの? | TypeTemplate(vector<TypeTemplate>)はvectorの型テンプレートで型を生成するコンストラクタによって初期化形式である必要があります。?何を言っているの? |