我已经检查了其他类似的问题,但我仍然无法摆脱这个问题。我试图将这个功能作为公共和私人。
我班上有一个函数removeALL:
课程取消
#ifndef STRINGSET_H
#define STRINGSET_H
#include <iostream>
#include <string>
#include "StringNode.h"
using namespace std;
class StringSet
{
public:
// Constructor: creates an empty set.
StringSet();
// Destructor.
~StringSet();
// Returns the number of elements in the set.
int size();
// Inserts 'element' into the set. If 'element' is contained in the
// set, this operation has no effect.
void insert(string element);
// Removes 'element' from the set. If 'element' is not in the set, this
// operation has no effect.
void remove(string element);
// Returns true if and only if 'element' is a member of the set.
bool contains(string element);
// A friend function for writing the contents of the set to an output stream.
friend ostream& operator <<(ostream& outs, const StringSet& set);
private:
void removeAll();
int fixing (string element);
NodePtr head; // pointer to the head of the linked list
};
#endif // STRINGSET_H
但是当我尝试在cpp文件中创建函数时,我得到错误:没有'void StringSet :: removeALL()'在类'StringSet'中声明的成员函数
cpp中的removeALL函数和标题
#include <iostream>
#include <string>
#include "StringSet.h"
using namespace std;
void StringSet::removeALL()
{
if(head == NULL){
cout << "The list is empty" << endl;
return;
}
while (NodePtr temp = head)
{
head = temp->getLink();
delete temp;
}
}
int StringSet::fixing(string element)
{
int temp = 0;
if(((element[0] == 'n') || (element[0] == 'N')) && ((element[1] == 'o') || (element[1] == 'O'))
&& ((element[2] == 't') || (element[2] == 'T')))
{
element.erase(0,3);
remove(element);
element.clear();
temp = 1;
return temp;
}
else return temp;
}
有没有人有解决方案? 提前谢谢!
答案 0 :(得分:2)
C ++区分大小写。 removeAll
和removeALL
是不同的事情。