【问题标题】:constructor syntax missing formal parameters构造函数语法缺少形式参数
【发布时间】:2018-01-20 20:40:34
【问题描述】:

我正在编写一个包含对象数组的类模板。 我收到一条错误消息,提示“构造函数语法缺少形式参数”。 该错误与代码行DT List[100]相关;

template <class DT>
class List
{
private:
    DT List[100];
    int numberInList;
    int listSize;
    int nextIndex;
public:
    List();
    void insert(DT&);
    DT getNext();
    bool getMember(DT&);
    int getNumber();
};
#endif

template<class DT>
List<DT>::List()
{
   numberInList = 0;
   listSize = 0;
   nextIndex = 0;
}

【问题讨论】:

标签: c++ class-template


【解决方案1】:

对于未来的读者(正如 @UnholySheep 在 cmets 中指出的那样),问题很可能源于成员 DT List[100];。类的名称是List 以及成员的名称。这可能会导致一些解析混乱。更改成员变量的名称应该可以解决该错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-21
    • 1970-01-01
    • 1970-01-01
    • 2021-05-27
    • 2016-03-08
    • 1970-01-01
    • 2011-04-27
    • 1970-01-01
    相关资源
    最近更新 更多