国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(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)成員變量的使用舉例的評論 (共 條)

分享到微博請遵守國家法律
乳山市| 南召县| 宝鸡市| 锡林郭勒盟| 东辽县| 饶阳县| 丽江市| 兴业县| 祁东县| 红安县| 平遥县| 蓬安县| 永康市| 黄陵县| 蕲春县| 浠水县| 阿瓦提县| 乌鲁木齐市| 邯郸县| 武定县| 景宁| 兴安县| 浮山县| 莱州市| 清河县| 西峡县| 延边| 收藏| 济南市| 高雄县| 西贡区| 麦盖提县| 白沙| 呼玛县| 新丰县| 墨玉县| 兴和县| 万年县| 绿春县| 涞水县| 万荣县|