有没有什么办法能获取is中的参数名coll1?

template <typename T>
class RuntimeCmp{
public:
enum cmp_mode {
normal,reverse
};
private:
cmp_mode mode;
public:
RuntimeCmp(cmp_mode m = normal) : mode(m){}
bool operator() (const T& t1,const T& t2) const{
return mode == normal ? t1<t2 : t2<t1;
}
bool operator==(const RuntimeCmp& rc){
return mode == rc.mode;
}
};

typedef set<int,RuntimeCmp<int> >intSet;
void fill(intSet& set){
set.insert(4);
set.insert(7);
set.insert(5);
set.insert(1);
set.insert(6);
set.insert(2);
set.insert(5);
}

void pr(intSet& is,string name){
std::cout<<name;

copy(is.begin(),is.end(),ostream_iterator<int>(cout," "));
cout<<endl;
}

//使用pr时,只带一个参数intSet& is,然后通过is的参数名来输出
比如:
intSet coll1;
fill(coll1);
pr(coll1);
直接就能输出coll1: 1,2,4,5,6,7
而不是pr(coll1,"coll1: ")这样的。

慕哥6287543
浏览 101回答 1
1回答

慕桂英546537

应该是没有任何方法的,毕竟编译后就完全不存在变量名.
打开App,查看更多内容
随时随地看视频慕课网APP