C++ overloading operators


yesterday skimmed large fraction of c++ book. through book use << iostreams. say, operator overloading syntactic sugar.

anyway, last night occurred me interesting try in liquidcrystal add kind of syntax. seems me worthwhile, i'd setcursor.

so thought i'd try implement syntactic sugar:
lcd<<"hello expresso machine";
lcd(8,3)<<"bye, now";

this mean overloading << tying print rather iostreams
and overloading () , tying setcursor.

i thought << both want return 'this' write:
lcd(0,0)<<"upper left"<<" "<<x;
i pared away trying compile , changed type of fcn void.

i realize need several overloaded versions of <<, mimicking in 'print', 1 seemed place start. have
code: [select]
void liquidcrystal::operator<< (const char str[]) {  //there half dozen overloaded versions of print
 liquidcrystal::print(str);
//  return this;
 }
 
//void liquidcrystal:operator() (uint8_t col,uint8_t row) {
void liquidcrystal:operator() (uint8_t col,uint8_t row)  {
 setcursor(0,row);
//  return this;
 }


and error left when compile refers operator():

/applications/arduino.app/contents/resources/java/libraries/liquidcrystal/liquidcrystal.cpp:337: error: function definition not declare parameters

i tried reducing 1 argument (ie row) , message didn't change. i've had little luck trying google info on overloading () , book have barely mentions operator. 1 instance of overloading () found looks pretty similar have. at:
http://www.parashift.com/c++-faq-lite/operator-overloading.html

the error msg says definition not declaration, completeness .h file has this:
code: [select]
     void operator() (uint8_t, uint8_t);
     void operator<<      (const char*);


with
code: [select]
liquidcrystal* operator() (uint8_t, uint8_t) const;
liquidcrystal* operator<<      (const char*);


and this
code: [select]
liquidcrystal* liquidcrystal::operator<< (const char str[]) {  //there half dozen overloaded versions of print
 liquidcrystal::print(str);
 return this;
 }

liquidcrystal* liquidcrystal:operator() (uint8_t col,uint8_t row) const {
 setcursor(col,row);
 return this;
 }


i've got return type compiling still no clue missing parameter thing.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > C++ overloading operators


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums