I have made two libraries and one test program.I have made my custom uart library.first i have included all functions for printing in single uart library file.but then i have made print library for printing functions only.my files are listed below.i have not posted my code directly so it can be read separately.






#include <avr/io.h>                                                          
#include "uart.h"

int main(){

and i get this error..


src/print.cpp: In member function 'void PrintClass::print(unsigned char)':
src/print.cpp:4:12: error: 'write' was not declared in this scope
src/print.cpp: In member function 'void PrintClass::print(char*)':
src/print.cpp:13:22: error: 'write' was not declared in this scope
.build/uno/Makefile:47: recipe for target '.build/uno/src/print.o' failed make: *** [.build/uno/src/print.o] Error 1
Make failed with code 2

i have referred default arduino libraries like hardwareSerial and LiquidCrystal and i made my library like that but i cant get rid of that. Please Help me.


Any functions that the base class needs to call that will be defined in the child class must also be defined in the base class. They should be defined "virtual" so they can be overridden, and can even be "pure virtual" so they have to be defined in the child class.

So for any function in the child class that the base class needs to access, add this to the base class's definition (print.h):

virtual void write(unsigned char data) = 0;

The = 0 bit defines it as pure virtual, and any classes than inherit this class without defining their own copy of the void write(unsigned char) function will thrown an error.

Instead of pure virtual you can provide a default function that a child can override if they want to, which can be useful if most classes will work the same way (define it in the parent) but some want to do it differently (override it in the child), in which case you treat it like a normal class function but add the virtual tag.

The whole topic is called polymorphism and is an incredibly powerful system. It's discussed in detail here: http://www.cplusplus.com/doc/tutorial/polymorphism/

  • if you dont mind,can you explain with my code..please
    – Mohit Tank
    Jun 15 '15 at 15:23
  • All you should need is the one line of code I show there - add it to print.h
    – Majenko
    Jun 15 '15 at 15:24
  • I dont know how can i thank you.thank you for helping again. :) .
    – Mohit Tank
    Jun 15 '15 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.