如何在 c++ 中访问类的私有数据成员
How to access private data members of a class in c++
以下代码在我的"struct node* createNode"函数第 30 行和第 31 行中显示两个错误。 错误是"临时"未声明和无效使用不完整类型的"结构节点"。如何解决这个问题??
#include <iostream>
using namespace std;
class myClass{
private:
struct node{
int data;
struct node *next;
};
struct node *head, *last, *temp;
public:
myClass();
bool isEmpty();
struct node *createNode();
void insertElement();
void deleteElement();
void displayList();
};
myClass::myClass(){
head=NULL;
last=NULL;
temp=NULL;
}
bool myClass::isEmpty(){
if(head==NULL)return true;
return false;
}
struct node *createNode(){
temp = new node;
return temp;
};
int main()
{
return 0;
}
从公共membre函数返回私有类型非常奇怪 但这是它是如何完成的
myClass::node *myClass::createNode(){
temp = new node;
return temp;
}
createNode(( 是 "myClass" 类的成员,将定义更改为:
node *myClass::createNode(){
temp = new node;
return temp;
}
并删除此函数后面的分号
相关文章:
- 用于访问容器<T>数据成员的正确 API
- 使用指针访问数组中的对象数据成员
- 友元函数无法访问私有数据成员 (c++)
- 在类 A 中创建类型为 B 类的向量 - 访问数据 [C++] [成员在两个类中都是私有的]
- 访问数据成员(本身是对象)的数据成员,就好像它们是类成员一样
- 使公共数据成员在C++中无法访问
- 有没有办法在C++中循环访问对象的不同数据成员
- 为什么类成员数据必须是静态的才能被模板化类的模板化结构成员访问
- 如何在C++中使用类对象访问指针数据成员
- 通过指针算法访问结构数据成员
- 是否可以访问类数据成员并在析构函数中对它们执行操作?
- 如何在 c++ 中访问类的私有数据成员
- 现代C++编译器是否优化了对类中同一数据成员的重复访问?
- 无法访问派生类函数内的基类的受保护数据成员
- 从私有结构数据成员访问类公共成员函数C++
- 有关C++/组件数据布局、数据成员访问、方法的一般问题
- C++ 共享库不允许静态数据成员访问
- 私人数据成员访问
- OpenCV Mat数据成员访问
- 数据成员访问歧义和菱形继承