I have a function which prints entries of a "Polynomial" class:
void Polynomial::print()
{
Term* pos = first;
while(pos != NULL){
std::cout << "y=" << pos->coeff << "x^" << pos->power;
if(pos->next != NULL){
std::cout << "+";
}
pos = pos->next;
}
std::cout<<endl;
}
and I would like to translate it so that I can use it with cout instead. I made the following friend function:
std::ostream & operator << (std::ostream &out, const Polynomial &Poly)
{
Term* pos = Poly.first;
while(pos != NULL){
out << "y=" << pos->coeff << "x^" << pos->power;
if(pos->next != NULL){
out << "+";
}
pos = pos->next;
}
out<<endl;
}
Which told me 'Term' was not declared in this scope
. Term is a private struct defined inside the class Polynomial , how do can I use it as a type inside the friend function?
Term
是在Polynomial
内部定义的,因此在Polinomial
类范围之外使用时,需要使用其全名Polynomial::Term
来引用它。
Polynomial::Term* pos = Poly.first;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.