Hello guys.I am trying to resolve one problem but i can'n.I have two classes:
class FileSystemElement and class Folder.Class FileSystemElement contains a pointer to a Folder(*Folder) and Folder contains array of FileSystemElement pointers.And also Folder is inherited from FileSystemElement,but it can't see it as a base class.I tried to put in one header file both headers but it didn't resolve a problem.
Short answer: in FileSystemElement.h, move #include "Folder.h" to the end of the file.
To see why this is isn't working, consider what happens when your program contains #include "FileSystemElement.h" :
- The preprocessor runs and sees #include "FileSystemElement.h"
- It starts processing FileSystemElement.h. At line 3 it's told to process "Folder.h"
- At line 3 of Folder.h, it's told to parse FileSystemElement.h" again. But [u]because FileSystemElement.h contains #pragma once and because you already started processing it,
that file is skipped.
- Moving along in Folder.h, it sees the forward declaration to FileSystemElement, but when you say that Folder is a public FileSystemElement, it doesn't know how big FileSystemElement is, so it generates an error.
By moving the #include "Folder.h" to the end of FileSystemElement.h, you ensure that FileSystemElement is defined by the time you declare Folder.
moving an include to the end of a file tickles my OCD
I hear ya. The other possibility is to remove the #include "Folder.h" from FileSystemElement.h and require the pogrammer to include Folder.h themselves, but that's messy too.