0

I'm currently using the SDFat library and am passing a global FatFile

enter image description here

I if have a function that requires an SdFile type and I know that a given instance of FatFile is a valid SdFile what is the best way to reopen FatFile F as SdFile J?

Right now I'm doing:

SdFile ActiveFile;  //Global Active File
...
void SDRun (FatFile &RunFat)
{
  SdFile RunRoot;
  RunRoot.open("/", O_READ);
  ActiveFile.close();
  ActiveFile.open(&RunRoot,RunFat.dirIndex(),O_READ);
  ....

However, this only works when RunFat is in the root directory.

1

If RunFat is an instance of SdFile you can just cast it:

SdFile& RunRoot = dynamic_cast<SdFile&>(RunFat);

RunRoot and RunFat are now the exact same file in the exact same state (no need to open it or anything) but seen as an SdFile not a FatFile.

  • Ok, doing SdFile& RunRoot = dynamic_cast<SdFile&>(RunFat); I get an error cannot dynamic_cast 'RunFat' (of type 'class FatFile') to type 'class SdFile&' (source type is not polymorphic) – ATE-ENGE Aug 30 '17 at 15:07
  • Did you make sure you got all the & in the right places? – Majenko Aug 30 '17 at 15:36
  • I have, I've also tried a few variants, but the dynamic cast continues to give me a source type is not polymorphic error. – ATE-ENGE Aug 30 '17 at 17:16
  • Maybe it's not a proper child->parent relationship then. Or it's not really a class, or something? – Majenko Aug 30 '17 at 17:23

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.