c ++类可以将自身作为一个属性吗? [英] Can a c++ class include itself as an attribute?
问题描述
我想通过在C ++中编写一个python例程来加快速度。然后使用ctypes
或cython。
我是c ++的全新。我正在使用microsoft express c ++,因为它是免费的。
我计划实现一个表达式树,并以后缀顺序来评估它的方法。
我立即遇到的问题是:
class Node {
char * cargo;
节点左;
节点权限;
}
我不能将节点类型左或右声明。
我愿意学习更多的c ++,因为我需要更多。
感谢您的帮助。
p>不,因为对象将是无限大(因为每个 Node
作为成员两个另外 Node
对象,每个对象都有两个其他 Node
对象,
但是,您可以有一个指向类类型的指针作为成员变量:
class Node {
char * cargo;
Node * left; //我不是节点我只是一个指向节点的指针
Node * right; // Same here
};
I'm trying to speed up a python routine by writing it in C++. then to use it using ctypes
or cython.
I'm brand new to c++. I'm using microsoft express c++ as it's free.
I plan to implement an expression tree, and a method to evaluate it in postfix order.
The problem I run into right away is:
class Node {
char *cargo;
Node left;
Node right;
}
I can't declare left or right as Node types.
I'm willing to learn as much c++ as I need and more. the reference material I have right
now does not address this problem.
Thanks for any help.
No, because the object would be infinitely large (because every Node
has as members two other Node
objects, which each have as members two other Node
objects, which each... well, you get the point).
You can, however, have a pointer to the class type as a member variable:
class Node {
char *cargo;
Node* left; // I'm not a Node; I'm just a pointer to a Node
Node* right; // Same here
};
这篇关于c ++类可以将自身作为一个属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!