c++ - 一个声明中有多种类型的问题

标签 c++ class unix

当我尝试编译时出现错误:

In file included from editorMain.cpp:2:0:
EditorList.h:40:2: error: multiple types in one declaration
 };
  ^
In file included from EditorList.cpp:4:0:
EditorList.h:40:2: error: multiple types in one declaration
 };
  ^
EditorList.h:40:2: error: multiple types in one declaration
 };
  ^

错误在某处:

#ifndef EDITORLIST_H
#define EDITORLIST_H

#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;

class EditorList

class Node
{
    friend class EditorList;
  private:
    Node *nextNode;
    int lineNum;
    string lineText;

  public:
    Node(void)
    : nextNode(NULL)
    {}

    Node(int val)
    : lineNum(val), nextNode(NULL)
    {}

    Node(int val,  Node* next)
    : lineNum(val), nextNode(next)
    {}

    int getLine(void)
    {return lineNum;}

    string getText(void)
    {return lineText;}

    Node* getNext(void)
    {return nextNode;}
};

class EditorList
{
  private:
    Node *head;
    Node *tail;

  public:
    EditorList(void);
    EditorList(int val);
    //-EditorList(void);

    void insertHead(int val);
    void insertInside(Node* inptr, int val);
    void insertEnd (int);
    Node* getNode(int pos);
    void deleteLine (int);
    void printText ();
    void displayMenu ();
    void saveQuit (); 
};

#endif  /* EDITORLIST_H */

我真的不确定是什么原因造成的,因为这是我唯一一次看到这个错误,我忘记了类定义后的分号,但这里似乎不是这种情况。感谢您的帮助。

最佳答案

不是 100% 确定,但我相信您需要一个 ;在类前向声明​​之后。

using namespace std;

class EditorList

class Node

应该是

using namespace std;

class EditorList;

class Node

关于c++ - 一个声明中有多种类型的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33093746/

相关文章:

linux - 使用 shell 命令从目录中删除旧备份

shell - 查找两个文件之间有多少行不同

linux - 打印一行,其中一个数字在第三个字段中重复了 n 次

c++ - 将 C 库与 C++ 链接

python - Cython:python int 到 uint8_t

c++ - 在 C++ 中,我可以拥有一个仅在特定条件下具有某些功能的类吗?

c++ - 指针错误 - "using uninitialized value"即使我认为它已初始化?

java - 在 kotlin 中沟通父类及其内部类的最佳方式是什么?

C++ 类继承顺序

python - 在 Python 中添加到自定义类