Inherit from Print class question

Hello,

I want to create a class that inherits from Print.h. I use my own implementation of write(uint8_t), so I define it.

class  myclass: public Print
{
  public:
  virtual size_t write(uint8_t);
};

size_t myclass::write(uint8_t b){
  ......defined
}

void setup() {
  // put your setup code here, to run once:
  myclass x;
  uint8_t y[]="hello";
  x.write(&y[0],10);
}

void loop() {
  // put your main code here, to run repeatedly: 
}

In my sketch I am trying to use virtual size_t write(const uint8_t *buffer, size_t size) method of the base class Print.h, but the compiler tells me there is no matching function. Valid candidates are write(uint8_t). Shouldn’t I have inherited this functionality from Print.h?

Thanks,

-diesel

Moderator edit: [code][/code] tags added. (Nick Gammon)

Are you using Arduino 1.0 or later?

You do know that the line:
x.write(&y[0],10);
will not call your defined method.

You defined a method that accepts a uint8_t as a parameter and you are calling a method with a pointer to a uint8_t and an int

BTW: as simpler way saying ( &y[0] ) is ( y ).

This compiles under 1.0 of the IDE:

class  myclass: public Print
{
  public:
  virtual size_t write(byte b);
};

size_t myclass::write(byte b){
 // ......defined
}

void setup() 
{
  myclass x;
  char y [] = "hello";
  x.print(y);
}

void loop() {}

Hello,

I am using Arduino 1.0. Yes, I know that I can call print,but I want to call write with a length specified. Yes, I am aware that I could have put in y. I tried x.write(y,(size_t)5); , still same issue. I don't understand.

Thanks,

-diesel

class myclass: public Print
{
public:
virtual size_t write(uint8_t);
using Print::write;
};

Coding Badly,

Thanks! I got it. The compiler finds the write function in the derived class, once found, doesn't search the base class for the function with the same name, gives an error. The "using Print::write;" instructs the compiler to search the base class. I found helpful link if anybody else encounters this.

-diesel