代码如下,为什么形参 const std::string & co 要用引用,直接const std::string co 不行吗,company = co,不是一样吗?
void stock::acquire(const std::string & co, long n, double pr) {
company = co;
if (n < 0) {
std::cout << "Number of shares can't be negative;"
<< company << "shares set to 0.\n";
shares = 0;
}
else
shares = n;
share_val = pr;
set_tot();
}
GCT1015
相关分类