是否合法/建議做這在C++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
這是否可以工作取決於你如何使用包括得分後衛很多('的#ifdef ...') – jogojapan
哎呀.. 。那些。我現在將它們放入 – Eliezer
[this]的可能重複(http://stackoverflow.com/questions/1021793/how-do-i-forward-declare-an-inner-class)? – Simon