第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

請(qǐng)問(wèn):下面程序?yàn)槭裁丛谶B接時(shí)有錯(cuò),而在不用類模板時(shí)又沒(méi)有錯(cuò)???

另外:operator() 、operator== 在程序中是究竟是怎樣被調(diào)用的#include <iostream> #include <set> using namespace std; template <class T> class RuntimeCmp { public: enum cmp_mode {normal, reverse}; private: cmp_mode mode; public: //constructor for sorting criterion //-default criterion uses value normal RuntimeCmp (cmp_mode m=normal) : mode(m) { } //comparision of elements bool operator() (const T& t1, const T& t2) const { return mode == normal ? t1 < t2 : t2 < t1; } //comparision of sorting criteria bool operator== (const RuntimeCmp& rc) { return mode == rc.mode; } }; //type of a set that uses this sorting criterion typedef set<int,RuntimeCmp<int> > IntSet; void fill (IntSet& Set) { //fill insert elements in random order Set.insert(4);  Set.insert(7); Set.insert(5); Set.insert(1); Set.insert(6); Set.insert(2); Set.insert(5); } template <class T> int main() { //create, fill, and print set with normal element order //-uses default sorting criterion IntSet coll1; fill(coll1); copy(coll1.begin(),coll1.end(),ostream_iterator<int>(cout," "));cout<<endl;RuntimeCmp<int> reverse_order(RuntimeCmp<int>::reverse); //create, fill, and print set with reverse element order IntSet coll2(reverse_order);  fill(coll2); copy(coll2.begin(),coll2.end(),ostream_iterator<int>(cout," "));cout<<endl;//assign elements AND sorting criterion coll1 = coll2; coll1.insert(3); // PRINT_ELEMENTS coll1copy(coll1.begin(),coll1.end(),ostream_iterator<int>(cout," "));cout<<endl;//just to make sure... if (coll1.value_comp() == coll2.value_comp()) { cout << "coll1 and coll2 have same sorting criterion" << endl; } else { cout << "coll1 and coll2 have different sorting criterion" << endl; } return 0;}
查看完整描述

2 回答

?
達(dá)令說(shuō)

TA貢獻(xiàn)1821條經(jīng)驗(yàn) 獲得超6個(gè)贊

根據(jù)你的出錯(cuò)信息來(lái)看,要么你沒(méi)有main,要么你有多余的main
這些運(yùn)算符的調(diào)用和函數(shù)是一樣的 
他們有參數(shù),也有返回類型,當(dāng)然并不是所有的都是這樣,如 operator type()就沒(méi)有返回類型,其實(shí)type就是,調(diào)用我也不太清楚.如class operator+(),如是全局的則()內(nèi)的一個(gè)是左操作數(shù),一個(gè)是右操作數(shù) ,class代表返回值,operator==類似

查看完整回答
反對(duì) 回復(fù) 2023-04-12
?
喵喔喔

TA貢獻(xiàn)1735條經(jīng)驗(yàn) 獲得超5個(gè)贊

沒(méi)寫(xiě)main函數(shù)唄

查看完整回答
反對(duì) 回復(fù) 2023-04-12
  • 2 回答
  • 0 關(guān)注
  • 160 瀏覽

添加回答

了解更多

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)