sách gpt4 ai đã đi

c++ - “节点”不是全局命名空间的成员?

In lại 作者:行者123 更新时间:2023-11-28 08:21:55 33 4
mua khóa gpt4 Nike

我不知道代码有什么问题,但在 visual studio 中不断收到这些错误消息。

Error 18 error C1903: unable to recover from previous error(s); 29
Error 15 error C2039: 'Node' : is not a member of '`global namespace'' 23
Error 6 error C2039: 'node_count' : is not a member of '`global namespace'' 13
Error 5 error C2039: 'node_count_' : is not a member of '`global namespace'' 10
Error 3 error C2059: syntax error : '<'
Error 13 error C2059: syntax error : '<' 23
Error 11 error C2086: 'int CS170::List' : redefinition 23
Error 7 error C2143: syntax error : missing ';' before '{' 14
Error 1 error C2143: syntax error : missing ';' before '<' 10
Error 9 error C2143: syntax error : missing ';' before '<' 23
Error 8 error C2447: '{' : missing function header (old-style formal list?) 14
Error 17 error C2588: '::~Node' : illegal global destructor 29
Error 2 error C2988: unrecognizable template declaration/definition 10
Error 12 error C2988: unrecognizable template declaration/definition 23
Error 4 error C3083: 'Node': the symbol to the left of a '::' 10
Error 14 error C3083: 'Node': the symbol to the left of a '::' must be a type 23
Error 16 error C3083: 'Node': the symbol to the left of a '::' must be a type 29
Error 10 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 23

这是头文件;

////////////////////////////////////////////////////////////////////////////////
#ifndef LIST_H
#define LIST_H
////////////////////////////////////////////////////////////////////////////////

#include /* ostream, endl */

namespace CS170
{
template class List;

template
std::ostream & operator<<(std::ostream & os, const List &list);

template
class List
{
công cộng:
// Default constructor
List(void);

// Copy constructor for constructing a list from an existing list
List(const List &list);

// Construct a list from a T array
List(const T *array, int size);

// Destructor
~List(void);

void push_front(const T& Value); // adds the item to the front of the list
void push_back(const T& Value); // adds the item to the end of the list
void pop_front(void); // removes the first item in the list
T front(void) const; // retrieves the first item in the list
int size(void) const; // returns the number of items in the list
bool empty(void) const; // true if empty, else false
void clear(void); // clears the list

// Overloaded assignment operator (=) for assigning one list to another
List& operator=(const List &list);

// Overloaded addition operator (+) for adding two lists
List operator+(const List &list) const;

// Overloaded addition/assignment (+=) for adding to a list "in place"
List& operator+=(const List &list);

// Overloaded subscript operators
const T& operator[](int index) const;
T& operator[](int index);

// Output operator for printing lists (<<)
friend std::ostream & operator<< (std::ostream & os, const List &list);

// Returns the number of Nodes that have been created
static int node_count(void);

riêng tư:
// Used to build the linked list
struct Node
{
Node *next; // pointer to the next Node
T data; // the actual data in the node
Node(T value); // non-default constructor (conversion)
~Node(void); // destructor
static int node_count_; // number of Nodes created
};

Node *head_; // pointer to the head of the list
Node *tail_; // pointer to the last node
int size_; // number of items on the list

// All nodes are created in this method
Node *new_node(const T& data) const;
};

} // namespace CS170

#include "List.cpp"

#kết thúc nếu
////////////////////////////////////////////////////////////////////////////////

这是cpp文件;

namespace CS170
{

// static members

template
int List::Node::node_count_ = 0;

template
int List::node_count(void)
{
return Node::node_count_;
}


// List::Node methods
template
List::Node::Node(T value) : data(value)
{
node_count_++;
}

template
List::Node::~Node(void)
{
node_count_--;
}

// public methods

template
void List::clear(void)
{
while (!empty())
pop_front();
}

// private methods

template
typename List::Node *List::new_node(const T& data) const
{
Node *node = new Node(data); // create the node
node->next = 0; // no next pointer yet
return node;
}

} // namespace CS170


// non-members

#include

template
std::ostream &CS170::operator<<(std::ostream & os, const CS170::List &list)
{
// Start at the top
typename CS170::List::Node *pnode = list.head_;

// Print each item
while (pnode != 0)
{
os << std::setw(4) << pnode->data;
pnode = pnode->next;
}
os << std::endl;
return os;
}

谢谢...

1 Câu trả lời

struct Node0 应该是 struct Node.

关于c++ - “节点”不是全局命名空间的成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5506419/

33 4 0
Bài viết được đề xuất: c++ - 如何在模板模板参数中使用默认参数以外的参数进行实例化
Bài viết được đề xuất: c++ - 可执行文件的 RPATH 等价物
Bài viết được đề xuất: C++ 计算问题,总是返回 $0
Bài viết được đề xuất: c++ - 确保一个小部件有一个容器?
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com