C ++ Define a class in one file and forward it in another
Is it legal / advised to do it in C ++
//Interface.h
#ifndef INTERFACE_H
#define INTERFACE_H
#include "WinImplementation.h"
#include "NixImplementation.h"
class Interface {
class WinImplementation;
class NixImplementation;
}
#endif
//WinImplementation.h
#ifndef WINIMPLEMENTATION_H
#define WINIMPLEMENTATION_H
#include "Interface.h"
class Interface::WinImplementation {}
#endif
//NixImplementation.h
#ifndef NIXIMPLEMENTATION_H
#define NIXIMPLEMENTATION_H
#include "Interface.h"
class Interface::NixImplementation {}
#endif
+3
source to share
1 answer
Yes, you can forward nested classes to C ++. The following example is taken directly from the C ++ standard (section 9.7.3):
class E
{
class I1; // forward declaration of nested class
class I2;
class I1 {}; // definition of nested class
};
class E::I2 {}; // definition of nested class
+1
user420442
source
to share