- 分享
- 0
- 人气
- 0
- 主题
- 0
- 帖子
- 32
- UID
- 65421
- 积分
- 31
- 阅读权限
- 11
- 注册时间
- 2007-3-1
- 最后登录
- 2009-10-3
- 在线时间
- 23 小时
|
//This is file LinkedList.cpp
#include "LinkedList.h"
#include <string>
#include <iostream>
#include <cstdlib>
#include <cassert>
using namespace std;
LinkedList::size_type LinkedList::count(const value_type& target) const
{
size_type answer;
const Node *cursor;
answer = 0;
cursor = list_search(head_ptr, target);
while(cursor!=NULL)
{
++answer;
cursor = cursor->next;
cursor = list_search(cursor,target); //<--------error
}
return answer;
}
//This is file LinkedList.h
#ifndef LinkedList_h
#define LinkedList_h
#include "Node.h"
#include <string>
#include <iostream>
#include <cstdlib>
using namespace std;
class LinkedList
{
public:
typedef Node::value_type value_type;
typedef std::size_t size_type;
LinkedList();
LinkedList(const LinkedList& source);
~LinkedList();
Node* list_search(Node* head_ptr, const Node::value_type& target);
void head_insert(const value_type& entry);
void tail_insert(const value_type& entry);
void operator += (const LinkedList& addend);
size_type size() const
{
return many_nodes;
}
size_type count(const value_type& target) const;
void list_copy(const Node* source_ptr, Node*& head_ptr, Node*& tail_ptr);
void list_clear(Node*& head_ptr);
Node* list_search(Node* cursor, const Node::value_type& target) const;
const Node* list_search(const Node* head_ptr, const Node::value_type& target);
private:
Node* head_ptr;
size_type many_nodes;
};
#endif /*LinkedList_h*/
//This is file Node.h
#ifndef Node_h
#define Node_h
#include <cstdlib>
#include <string>
class Node
{
public:
//Tupedef
typedef std::string value_type;
typedef std::size_t size_type;
//Constructor
Node();
Node(const value_type& init_data = value_type(), Node* init_link = NULL)
{
data_field = init_data;
link_field = init_link;
}
Node* next;
private:
value_type data_field;
Node *link_field;
};
#endif /* Node_h */
出现了
"LinkedList.cpp:In member function 'size_t LinkedList::count(const std::string&) const':
Linkedlist.cpp:45 : error: passing 'const Linkedlist' as 'this' argument of 'const Node* LinkedList::list_search(const Node*, const std::string&)' discard qualifiers
我试过很改了很多次,还是不知道怎么改。。。
请帮帮忙。。。。。
[ 本帖最后由 alphading 于 2009-9-12 08:55 AM 编辑 ] |
|