如何访问另一个类中的内部类
How do you access inner classes within another class?
我在另一个类中有一个节点类,该类在结构类中是私有的,这是我正在使用的主要类。然后,我在另一个。cpp文件中实现了Structure .h文件中的函数,该文件包含了Structure类和Node类,嵌套在Structure类中的private。
在创建Node*的返回类型时如何访问该Node类?我已经摆弄了一段时间了,但什么也不管用。它允许我返回int, bool, double类型,但不能返回Node*。
"Structure.h"
template <class T>
class Structure
{
public:
// Structure functions();
private:
class Node
{
public::
// Node functions and variables;
}
// Structure functions_private();
}
你的意思是:
template< class T >
typename Structure<T>::Node* Structure<T>::MyMemberFunction()
{
return new Node();
}
举个例子
你还需要把它放在你的头文件中,而不是在源代码中
在类定义中,您可以简单地将该类型称为Node
。
外部,您需要限定名,如果它依赖于模板参数,则需要typename
:
Structure<int>::Node * some_function(); // not dependent, no typename
template <typename T>
typename Structure<T>::Node * some_template(); // dependent, needs typename
相关文章:
- 从另一个 cpp 文件更改结构内、映射键内的变量
- 有没有办法使用该类的构造函数初始化另一个类的私有部分内的对象数组?
- GLM如何在不声明内联函数并在另一个(未连接的?)文件中将其定义的函数逃脱
- 如何在另一个名称空间内从另一个命名空间内明确专业化功能模板
- C 和 C++ 标头:在另一个结构内定义全局结构
- 无法更改另一个窗口内窗口的背景颜色
- 在矢量内创建一个对象,该对象由另一个对象包含
- C++ MySQL,使用在同一类内的另一个函数中的一个函数中建立的连接
- 在另一个结构中的结构内解除分配指针
- Visual C 和内联装配代码在一个程序中具有相同的输出,但在另一个程序中具有不同的输出
- 如何调用其原型在另一个函数中范围内的函数
- 分段错误 - 更改结构(在另一个结构内)变量
- 如何确定另一个结构内的结构阵列的长度
- 在一个线程内进行的赋值在另一个线程中不可见
- 如何检查一个范围内的值是否是另一个范围内的值的倍数
- 将内部类名声明为另一个声明的一部分
- 如何识别模板参数参数是否是模板内结构中另一个类的实例?C++
- 无法正确访问在另一个类的私人区域内声明的类
- C++从另一个 cpp 文件调用内联函数
- 如何访问另一个类中的内部类