【发布时间】:2013-04-23 20:10:09
【问题描述】:
我有一个模板类,一旦它得到一个string 作为T,另一个Para* 作为T。
我已经为Para 重载了<<。
friend ostream& operator<< (ostream &wyjscie, Para const& ex){
wyjscie << "(" << ex.wrt << ", " << ex.liczbaWystapien <<")"<< endl;
return wyjscie;
}
所以要打印它我必须使用cout<<*objectOfClassPara<<endl; 否则我会打印
地址,但我不能为string 这样做。
如何更正此代码udner?
T t = n->key;
//cout<<n->key<<endl;
cout<<t<<endl;
if (is_same<T, Para*>::value){
cout<<*t<<endl; //IILEGAL INDIRECTION
}
【问题讨论】:
-
t不是指针,那你为什么要取消引用它呢? -
@0x499602D2 因为它有时是......在它下面我们有
Para* variable
标签: c++ templates indirection