当我尝试编译时出现错误:
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/