C++:访问头实现文件中的类属性
C++: Accessing class properties in header implementation file
我正在尝试实现双链接列表数据结构,因此我创建了一个具有类型为Node
的私有属性node
的类,当我尝试使用this
关键字从函数实现访问此属性时,应用程序失败。我需要帮助
LinkedList.hpp 的头文件
#include <stdio.h>
template<class T>
class LinkedList{
private :
struct Node{
T value;
Node* next;
Node* prev;
}node;
public :
LinkedList();
LinkedList(T item);
void add(T item);
// void get();
// void insert();
// void remove();
};
下面是头文件的实现。
#include "LinkedList.hpp"
template<class T>
LinkedList<T>::LinkedList(){
}
template<class T>
LinkedList<T>::LinkedList(T item){
}
template <class T>
void LinkedList<T>::add(T item){
Node* node = new Node;
node->value = item;
node->prev = NULL;
//Where the error is being generated
node->next = this.node;
};
返回的错误显示:
/Users/mac/Documents/LinkedList/LinkedList/LinkedList.cpp:27:22: Member reference base type 'LinkedList<T> *' is not a structure or union
this
是一个指针,正如错误消息所指出的那样。
用途:
this->node
相关文章:
- QML:修改在不同QML文件(而非main.QML)中定义的子对象的属性
- 如何通过一个循环将多个文件的内容分配给不同的类属性?
- 即使使用 FILE_FLAG_DELETE_ON_CLOSE 属性创建文件,文件也会保留在磁盘上
- My Project的属性配置正确,但Visual Studio仍然无法打开包含头文件
- MSBuild 由于缺少属性文件(可能与 IDE 相关)而无法生成 Visual Studio 项目
- 如何在 C++ 中使用提升属性树从 JSON 文件中读取对象数组
- 是否可以在 c++ 中创建一个文件并为其提供属性以将其隐藏?(在 Ubuntu 上)
- 访问除main.cpp之外的.cpp文件中的QMLEngine/rootObject属性
- 如何将目录中的文件属性填充到结构向量中?
- pybind11:属性错误:尝试从 py 文件运行函数时,模块'XXX'没有属性'YYY'
- 如何在Log4CPP属性文件中使用环境变量
- 使用setW()函数保存文件时,如何获取每个属性的值
- 如何创建属性存储二进制文件
- 使用提升属性树检查 xml 文件中是否存在元素
- 设置文件属性成功,但检索其失败
- FAT32和NTF中的自定义文件属性
- 如何使用Boost C 属性映射从配置文件中提取值
- POCO - 属性文件配置保存方法始终使用 ":" 作为分隔符进行写入
- 运行时未读取log4cplus属性文件更改
- 我可以同时使用属性文件和运行时配置配置log4cxx吗?