【发布时间】:2018-01-04 12:02:24
【问题描述】:
如何在此类的定义中为冗长的类名创建别名?我不希望它在类定义之外可以访问。我无法让它与typedef 或using 一起使用。
就我而言,这是一个类模板。
template<typename T>
class detailed_class_name{
typedef detailed_class_name<T> foo; // either one
using foo = detailed_class_name<T>; // of these
public:
foo(); // Error: ISO C++ forbids declaration of 'foo' with no type.
};
有什么想法吗?
【问题讨论】:
-
foo();应该是构造函数的声明吧?你不能。 -
你不能重命名构造函数或析构函数。如果这个类的名字让你感到困扰,也许它应该重命名?
-
类名被选择为描述性的,这使得它在这种情况下很长(一种具有非常特殊功能的链表)。我只是希望类声明尽可能简洁明了,没有长的类名。我认为确定类是关于什么的注释可以让我在其声明的其余部分缩写它的名称。我怀疑使用
ll而不是linked_list_with_special_invariances_for_a_number_of_special_cases会受到使用它的其他人的赞赏。