Open Parent Class as Child Class (SD Fat Library) I'm currently using the SDFat library and am passing a global FatFile



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 &amp;RunFat)
{
  SdFile RunRoot;
  RunRoot.open("/", O_READ);
  ActiveFile.close();
  ActiveFile.open(&amp;RunRoot,RunFat.dirIndex(),O_READ);
  ....


However, this only works when RunFat is in the root directory.
If RunFat is an instance of SdFile you can just cast it:

SdFile&amp; RunRoot = dynamic_cast&lt;SdFile&amp;&gt;(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.