Problem extending tinyFAT

Hello everybody,

I wish to extend capabilities of the class tinyFAT. For instance, to add a method allowing to create a file from a String variable. the code is as follows :

#include <tinyFAT.h>

class TinyFAT_M: public tinyFAT {
public:
  TinyFAT_M();
  boolean create(String fc);
};

TinyFAT_M::TinyFAT_M() : tinyFAT() {
}

boolean TinyFAT_M::create(String fc) {
  char buf[fc.length()+1];
  fc.toCharArray(buf, fc.length()+1);
  create(buf);
}

TinyFAT_M mySD;

void setup() {

  mySD.initFAT(); // it semms that this is oK ?
  String fch = "NewTexte";
  mySD.create(fch);
}

void loop() {

}

This compiles fine, but no file is created when launched.

Some ideas the reason why ?

Thank you for your help.

Pierre

What is the create() function that you call on TinyFAT_M::create() member?

I think it's necessary to close the file.

nid69ita:
What is the create() function that you call on TinyFAT_M::create() member?

I read in a C++ course that the compiler was able to distinguish bewteen several methods with the same name provided that the parameters were different in type or number. So I thought that this was true even if one method was in the parent class and the other in a child class Seemingly, it is not the case.

I have replaced, in my child class the method name "create" by "createSD" and now, it works.

But, is there a way to keep the same name in the two classes. For instance to use a special term (inherited in Pascal) to call the method of the parent class ?

nid69ita:
...I think it's necessary to close the file.

I don't understand what you mean

Ok, you want call the parent method, try adding "tinyFAT::"

boolean TinyFAT_M::create(String fc) {
  char buf[fc.length()+1];
  fc.toCharArray(buf, fc.length()+1);
  tinyFAT::create(buf);
}

I think it's necessary to close the file.

Only if it is actually opened. I don't think create() opens the file.

PaulS:

I think it's necessary to close the file.

Only if it is actually opened. I don't think create() opens the file.

Yes, the create() of base library not open the file.
I thought the "create ()" function was created by @ChPr and not the parent method.

Thank you for this information.

My method create() is the same that the tiyFAT's one but I use a String parameter instead of a char *.

Sincerely.

Pierre