Hi everyone , i have a few questions about the code that i post below.
1.Well i have to use the overload of the << operator but i can't change some parts of the code :
1 how i use the << operator without call the method etiquette , for exemple if want to print an object of Flacon1 f1
like
cout<<f1;
without pass f1.etiquette(cout);
2. I know that my changes have to been in the function print() , but i don't know how to associate the parametres.
If i do that , i have an infiniteloop , normaly the method print cout is an instance of oestream so, the overload of << operator (todo the printer ) is an external overload , so for that reason we need print / etiquette to have an cces to the atributs of the instance afficher(), but i don't know how to implement this situation.
has a very big problem. You name the function parameter "cout". Global scope has name "std::cout". The "using namespace std;" has created shortcut "cout". When you then use in your function body "cout", which "cout" do you think that you are referring to and which "cout" do you think that the compiler will refer to? (Unless it resorts to Error: unambiguous.)
Would you write:
1 2
int x = 7;
x = x;
No, Flacon::print has nothing to do with std::cout. It does receive a reference to some output stream (could very well be a file).
I wrote:
What should the print() print out?
should
I did not ask what error your current erroneous code produces. I did ask what that program should print.
If i do what you propose i should see something like this:
Eau :600 ml,pH 7.0
And it's fine but what i need is that i should be capable to see the same think just calling f1
like this for example:
cout << f1;
So i just resolved using the fonction etiquette() in the declaration of the << operator:
ostream& operator<<(ostream& out, Flacon c )
{
c.print(out);
c.etiquette(out);
return out;
}
So i changed the value or return there is not a constant anymore , and i used the method etiquette ().
With this implementation i solved the problem ,now about the use of cout like a parameter well honestly i use this name but i could use another one i mean i don't have any problem with this.
Now , Why i use print() and not only etiquette()?, well because etiquette is a chaine of characters specific but print one by one the values of the members of the class.
But now i have a problem when i printed , i see this :
Si je mélange
"0x6020a8Eau : 600 ml, pH 7"
avec
"0x6020a8Acide chlorhydrique : 500 ml, pH 2"
j'obtiens :
Si je mélange
"0x6020a8Acide chlorhydrique : 500 ml, pH 2"
avec
"0x6020a8Acide perchlorique : 800 ml, pH 1.5"
j'obtiens :