问题
Recently I asked the question about the hierarchy header file writing here. I got the answer, and marked it as the solution. But after a while I have additional question on this topic. What about the nested types? I want that at my header file of the types hierarchy there were also nested types displayed. For example (read the TODO, please):
/*
hierarchy.h
© Andrey Bushman, 12 July 2013
This file contains the full hierarchy of this application's types. This file
must be included into the each header file of this application.
*/
//-----------------------------------------------------------------------------
#ifndef BUSH_HIERARCHY_H
#define BUSH_HIERARCHY_H
#include <iostream>
#include <string>
#include <exception>
//*****************************************************************************
namespace Bushman{
//*****************************************************************************
namespace Common{
// run-time checked narrowing cast (type conversion)
template <class R, class A> inline R narrow_cast(const A& a);
// Throw the exception with the msg message.
void error(const std::string& msg);
}
//*****************************************************************************
namespace CAD_Calligraphy{
class Shp_istream; // Stream for SHP file reading.
class Shp_ostream; // Stream for SHP file writing.
class Token; // Token of the SHP file.
// TODO: The next both rows is not allowed (for nested types):
enum Token::Type; // Type of Token item.
class Token::Some_inner_class; // Class for internal use in the Token.
}
//*****************************************************************************
}
#endif
Without the nested types my types hierarchy will not be complete. How can I solve this problem?
P.S. I can write in the comments an info about the nested types. I think this is single solution. Am I right?
Thank you.
回答1:
You cannot forward nested types. As a workaround you can move them to separate namespace, but that is all.
来源:https://stackoverflow.com/questions/17613383/how-can-i-declare-the-nested-types-in-my-hierarchy-header-file