五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

類的靜態(tài)成員變量的使用舉例

2023-04-18 21:41 作者:盧朓  | 我要投稿

/**? a.cpp 的內(nèi)容如下:
?* 類的靜態(tài)成員變量.
?*? 編譯鏈接命令
?*? g++ -o a.out a1.cpp -std=c++11
?*
?*/

#include <iostream>
#include <string>
#include <map>

namespace tiao{

?? ?class A {
?? ??? ?public:
?? ??? ?static std::map<std::string, int> map1;
?? ??? ?static std::map<std::string, int> map2;
?? ??? ?int some_int;
?? ?};
};
/**
?* 如果注釋調(diào)下面兩行,編譯時會報錯:
?* Undefined symbols for architecture arm64:
? "tiao::A::map1", referenced from:
????? _main in a1-b57425.o
? "tiao::A::map2", referenced from:
????? _main in a1-b57425.o
ld: symbol(s) not found for architecture arm64
?*/
std::map<std::string, int> tiao::A::map1;
std::map<std::string, int> tiao::A::map2;

int main(){
?? ??? ?tiao::A::map1.insert(std::make_pair(std::string("kshg"), 3));
?? ??? ?tiao::A::map2.insert(std::make_pair(std::string("ksh"), 3));
? ??? ?tiao::A? A1;
?? ??? ?auto it1 = tiao::A::map1.find(std::string("ksh"));
?? ??? ?if(it1 == tiao::A::map1.end()) {
?? ??? ??? ?std::cout<<"在map1 中沒有找到 ksh"<<std::endl;
?? ??? ?}
?? ??? ?auto it2 = tiao::A::map2.find("ksh");
?? ??? ?if(it2 != tiao::A::map2.end()) {
?? ??? ??? ?std::cout<<"在map2 中找到 ksh"<<std::endl;
?? ??? ??? ?std::cout<<"key: "<< it2->first << "; value: " <<it2->second <<std::endl;
?? ??? ?}

?? ??? ?return 0;
}


類的靜態(tài)成員變量的使用舉例的評論 (共 條)

分享到微博請遵守國家法律
松阳县| 宣威市| 昆明市| 抚远县| 吉林市| 谢通门县| 钦州市| 天峻县| 耒阳市| 永和县| 兴化市| 开阳县| 射阳县| 棋牌| 白山市| 论坛| 高雄县| 通州市| 塔城市| 文山县| 新乐市| 吉林省| 洛隆县| 乌兰浩特市| 遵义县| 乳源| 大冶市| 太仆寺旗| 和政县| 沅陵县| 沂南县| 丹江口市| 宣恩县| 岢岚县| 上栗县| 吴堡县| 皮山县| 青田县| 广宗县| 南木林县| 崇左市|