在 C++11 中,以下注释处哪几行代是码合法的() #include <iostream> #include <unordered_map> #include <map> typedef long long ll; using namespace std; int main() { unordered_map<ll, pair<ll, ll>> un; un.insert(1, 2, 3); // 1 un.insert(make_pair(1, std::make_pair(2, 3))); // 2 un.emplace(1, 2, 3); // 3 un.emplace(1, make_pair(2, 3)); // 4 return 0; }
区块链毕设网qklbishe.com为您提供问题的解答
在 C++11 中,以下注释处哪几行代是码合法的()
#include <iostream> #include <unordered_map> #include <map> typedef long long ll; using namespace std; int main() { unordered_map<ll, pair<ll, ll>> un; un.insert(1, 2, 3); // 1 un.insert(make_pair(1, std::make_pair(2, 3))); // 2 un.emplace(1, 2, 3); // 3 un.emplace(1, make_pair(2, 3)); // 4 return 0; }
这个题目主要考察的c++11的标准库 关联容器 set map 等的操作
代码首先声明了一个无序map,内部的value_type是pair<ll, pair<ll, ll>> ,也就是一个嵌套的pair。 其中ll指long long
insert具有几种常用的重载,常见的
insert(elem) // 简单直接插入容器对应的元素类型 insert(pos, elem) // 指定位置插入, pos是一个迭代器 // emplace方***直接利用传入的参数构造需要的容器元素类型, 比如传入key_type和mapped_type emplace(args) // 指定位置 emplace(pos, args) // 同理 只是emplace对于multi-xxxx一定会插入 //对于非重复的只有不存在时才插入 insert(begin, end) // 插入迭代器范围内的元素,比如vector的cbegin和cend insert({xxxx,xxx}) // 批量插入一个花括号内的多个elem
由此可知,1是错误, map插入元素需要手动使用make_pair<xxx, xxx>的类型才可以,或者使用{xxx, xxx}构成pair。
2正确。
3也错误,没有对应的重载类型 需要的key_type为ll, mapped_type为pair<ll, ll> ,这两个会被emplace构造成value_type pair<ll, pair<<ll, ll>>>
复合要求。
如果是考虑带迭代器的重载话,数字无法符合类型要求。
59:39
以上就是关于问题在 C++11 中,以下注释处哪几行代是码合法的() #include <iostream> #include <unordered_map> #include <map> typedef long long ll; using namespace std; int main() { unordered_map<ll, pair<ll, ll>> un; un.insert(1, 2, 3); // 1 un.insert(make_pair(1, std::make_pair(2, 3))); // 2 un.emplace(1, 2, 3); // 3 un.emplace(1, make_pair(2, 3)); // 4 return 0; }的答案
欢迎关注区块链毕设网-
web3一级市场套利打新赚钱空投教程
区块链NFT链游项目方科学家脚本开发培训
从业7年-专注一级市场
微信:btc9767
TELEGRAM :https://t.me/btcok9
具体资料介绍
web3的一级市场千万收益的逻辑
进群点我
qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台-javagopython毕设 » 在 C++11 中,以下注释处哪几行代是码合法的() #include <iostream> #include <unordered_map> #include <map> typedef long long ll; using namespace std; int main() { unordered_map<ll, pair<ll, ll>> un; un.insert(1, 2, 3); // 1 un.insert(make_pair(1, std::make_pair(2, 3))); // 2 un.emplace(1, 2, 3); // 3 un.emplace(1, make_pair(2, 3)); // 4 return 0; }
微信:btc9767
TELEGRAM :https://t.me/btcok9
具体资料介绍
web3的一级市场千万收益的逻辑
进群点我
qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台-javagopython毕设 » 在 C++11 中,以下注释处哪几行代是码合法的() #include <iostream> #include <unordered_map> #include <map> typedef long long ll; using namespace std; int main() { unordered_map<ll, pair<ll, ll>> un; un.insert(1, 2, 3); // 1 un.insert(make_pair(1, std::make_pair(2, 3))); // 2 un.emplace(1, 2, 3); // 3 un.emplace(1, make_pair(2, 3)); // 4 return 0; }
进群点我
qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台-javagopython毕设 » 在 C++11 中,以下注释处哪几行代是码合法的() #include <iostream> #include <unordered_map> #include <map> typedef long long ll; using namespace std; int main() { unordered_map<ll, pair<ll, ll>> un; un.insert(1, 2, 3); // 1 un.insert(make_pair(1, std::make_pair(2, 3))); // 2 un.emplace(1, 2, 3); // 3 un.emplace(1, make_pair(2, 3)); // 4 return 0; }
qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台-javagopython毕设 » 在 C++11 中,以下注释处哪几行代是码合法的() #include <iostream> #include <unordered_map> #include <map> typedef long long ll; using namespace std; int main() { unordered_map<ll, pair<ll, ll>> un; un.insert(1, 2, 3); // 1 un.insert(make_pair(1, std::make_pair(2, 3))); // 2 un.emplace(1, 2, 3); // 3 un.emplace(1, make_pair(2, 3)); // 4 return 0; }