【发布时间】:2014-02-04 17:09:12
【问题描述】:
我已经检查了其他类似的问题,但我仍然无法摆脱这个问题。我试图将这个功能同时作为公共和私有。
我的班级中有一个函数 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 文件中创建函数时,我收到错误:没有在类 'StringSet' 中声明的 'void StringSet::removeALL()' 成员函数
RemoveALL 函数和 cpp 中的标头
#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;
}
有人有解决办法吗? 提前致谢!
【问题讨论】:
标签: c++ function linked-list