Hi,
I've been trying to write a library that will have all the features of the 'File' class but with a few extra functions for manipulating files. Based on my limited understanding I have attempted to base my new class on the 'File' class using this syntax for my class definition....
class FileFunctions:public File
{
public:
From what I've read, I though this should mean that my 'FileFunctions' class will automatically inherit methods like flush() and close() without the need for me to actually type the code in.
So far so good, my new library compiles OK, uploads Ok and the test sketch executes without visible errors. However, when I check the contents of my SD card, I discovered that the file I've created does exist but is empty.
Having played with arduinos with SD cards, I know this typically means that the open() has worked ok, but the close() hasn't. I have checked my sketch, and after writing each line of data to the file I flush() and close() it.
Since I haven't explicitly coded flush() and close() I expected these methods to be inherited from the parent class. However, in this case it doesn't seem to work. (to clarify - my class has inherited close() and flush() but they don't actually do anything! To prove this, I manually added these two functions to my class....
void FileFunctions::flush(void)
{
_myFile.flush();
}
void FileFunctions::close(void)
{
_myFile.close();
}
This time the library works, and data gets written to the file.
Have I missed something, maybe I have misunderstood inheritance? If I'm wrong, what's the point of inheritance if I've got to type in a link to the underlying function anyhow?
Thanks