Go Down

Topic: &operator (Read 699 times) previous topic - next topic

tuxduino

Operator overloading works like function / method overloading. So if you define << (char c) that version will be called when there's a char (literal or variable) on its right, like in the example made a couple of posts ago:

Code: [Select]
MyTinyGps << 'a' << 'b' << 'c';

If you want to be able to use string literals (i.e. C-type strings), you have to define another version of << which accepts const char*. Then you can use code like:

Code: [Select]
MyTinyGps << "abc";

johncc


Then you can use code like:
Code: [Select]
MyTinyGps << "abc";


(To OP) Or even

Code: [Select]
MyTinyGps << "abc: " << 13 << ',' <<" value: " << myFloat << endl;

Which would imply similarly overloaded operators taking a parameter of integer, float, and a variable "endl" which presumably contains a newline character...

Cheers,
John

tuxduino

And btw, presumably
Code: [Select]
encode(c); will add c to some internal data structure, like a temporary buffer that the parser will eventually, ehm... parse.

Go Up