![]() |
#2
笑傲2013-05-08 20:01
|

class CheckoutRecord{
public:
//....
private:
double bood_id;
string title;
Date date_borrowed;
Date date_due;
pair<string,string>borrower;
vector< pair<string,string>* > wait_list;
};
public:
//....
private:
double bood_id;
string title;
Date date_borrowed;
Date date_due;
pair<string,string>borrower;
vector< pair<string,string>* > wait_list;
};
有这样一个简单类
,在为它定义下标操作符,

pair<string,string>borrower& CheckoutRecord::operator[](const size_t index){
return *wait_list.at(index);
}
const pair<string,string>borrower& CheckoutRecord::operator[](const size_t index)const{
return *wait_lis.at(index);
}
return *wait_list.at(index);
}
const pair<string,string>borrower& CheckoutRecord::operator[](const size_t index)const{
return *wait_lis.at(index);
}
为什么要返回指针的解引,
而不是返回指针,
我知道可以返回指针,但不能返回局部对象的指针。