fl <
rxj...@gmail.com> wrote in
news:3dbc21a7-9b9a-4c3b...@googlegroups.com:
> Hi,
>
> I am learning C++ with an example, see below please.
> I find the friend function about >> redefinition in the class
> Item_base. I think that it is similar to a friend function, is it
> right?
Sorry, cannot parse that. Do you wanted to ask if user-defined operator>>
is similar to a function? Yes, it is.
And nothing is redefined here. The type Item_base is specific to your
program, if there appears a function which takes an argument of that
type, then it is a new function and specific to your program, not a
redefinition. If it has common name with some other functions
("operator>>" here), then it is called an overload. It still is a
distinct function as parameter types are part of the function signature
in C++.
> But I cannot find the operator '>>' function definition in the
> project, which can be built and run.
Then probably the program does not use this function. If a function is
never used then its definition is allowed to be absent.
> I am worry about the std >> operator cannot understand the second
> parameter
There is no "std >> operator". There are several operator>> overloads,
some declared by the standared headers, one declared in your program. Not
sure which one you are worried about and why.
>
> Item_base&
>
> Sales_item item5(Item_base("def", 35));
>
>
> double total = sale.total();
> cout << "Total Sale: " << total << endl;
>
>
> I am still new to C++. Whether operator >> has been derived to the
> Basket class?
One says "derived from", not "derived to". And one derives classes, not
operators. And no, Basket is not derived from anything and does not even
contain an operator>> declaration.
The line
cout << "Total Sale: " << total << endl
uses 3 different operator<< overloads, all defined in standard headers.
As there is no object of type Item_base appearing after any <<, your
operator<< overload is not used.
hth
Paavo