如何缩短内部 class 私有的 return 类型中的嵌套命名空间?
How to shorten nested namespaces in a return type which is private to an inner class?
这个问题是关于在 .cpp
文件中 return 类型的方法中处理长嵌套的私有 class 命名空间。
previous questions on 避免在 cpp
文件中使用长名称和嵌套命名空间,但它们似乎没有涵盖我的用例。
我有一个私有 nested class,在 header .h
文件中有一个特定于 class 的私有类型,如下所示:
class outer {
class inner {
typedef map<int, map<int, int>> footype;
private:
footype manipulate_foos(footype f1, footype f2);
}
}
在 .cpp
文件中定义方法时,如果我不使用指向 return 类型的名称空间的完整路径,编译器会报错,即使名称空间是在参数类型中推断出来的。所以我必须写一些类似
的东西
outer::inner::footype outer::inner::manipulate_foos(footype f1, footypte f2) {
// body
}
在我的例子中,这需要将 return 类型和方法名称拆分成多行,而且难以阅读。
问题
当 return 类型对内部 class 私有时,是否有任何方法可以省略该类型中的命名空间?
备注
明确地说,我不想省略方法名中的名称空间;我理解这些的价值,我觉得它们不会妨碍可读性,而 return 类型中的名称空间正在损害可读性。由于这是一个私有方法,我认为拼写完整的 return 类型没有帮助。
到目前为止,我在 .cpp
文件中尝试了以下解决方案:
using footype = outer::inner::footype
但它给了我错误 'class outer::inner::footype' is private within this context.
这似乎有效:
auto outer::inner::manipulate_foos(footype f1, footype f2) -> footype { ... }
这个问题是关于在 .cpp
文件中 return 类型的方法中处理长嵌套的私有 class 命名空间。
previous questions on 避免在 cpp
文件中使用长名称和嵌套命名空间,但它们似乎没有涵盖我的用例。
我有一个私有 nested class,在 header .h
文件中有一个特定于 class 的私有类型,如下所示:
class outer { class inner { typedef map<int, map<int, int>> footype; private: footype manipulate_foos(footype f1, footype f2); } }
在 .cpp
文件中定义方法时,如果我不使用指向 return 类型的名称空间的完整路径,编译器会报错,即使名称空间是在参数类型中推断出来的。所以我必须写一些类似
outer::inner::footype outer::inner::manipulate_foos(footype f1, footypte f2) { // body }
在我的例子中,这需要将 return 类型和方法名称拆分成多行,而且难以阅读。
问题
当 return 类型对内部 class 私有时,是否有任何方法可以省略该类型中的命名空间?
备注
明确地说,我不想省略方法名中的名称空间;我理解这些的价值,我觉得它们不会妨碍可读性,而 return 类型中的名称空间正在损害可读性。由于这是一个私有方法,我认为拼写完整的 return 类型没有帮助。
到目前为止,我在
.cpp
文件中尝试了以下解决方案:using footype = outer::inner::footype
但它给了我错误
'class outer::inner::footype' is private within this context.
这似乎有效:
auto outer::inner::manipulate_foos(footype f1, footype f2) -> footype { ... }