I have a parent class called Token
I have two children classes, ErrorToken and EndToken. Each one of those classes needs to be able to create an object of the other, and return it through a function call. Each one has their own seperate header class.
So, ErrorToken needs to be able to create a new EndToken object and return it, and EndToken needs to be able to create a new ErrorToken object and return it.
What is going to be the best way to succeed at doing this? I would prefer if it was as cross compiler compatible as possible so I don't want to use pragma once. (but thats essentially what I'm looking for).
Ideally I'd like to be able to do something like this...
#ifndef ErrorToken
#include "ErrorToken.h"
#endif
But that never seems to work (and my guess is that that is wrong? can someone help me understand why?).
My understanding of forward declaration is that it only works on function signatures and pointers (is that correct?), so I don't think that will work for my situation since I need it to be able to run the constructor...or does the compiler just need to be aware that the constructor exits at that moment?