I'm trying to speed up a python routine by writing it in C++, then using it using ctypes or cython.
I'm brand new to c++. I'm using Microsoft Visual C++ Express 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.
No, you can't do that. Cell is an incomplete type until the closing brace of the class definition. You can't instantiate a standard container over an incomplete type.
Class members are initialized in constructors which can be overloaded with different signatures. For classes that do not have constructor, a default constructor that initializes the class members (to default values) will be generated. Unlike in C++, C# allows a class to inherit from one base class only.
In addition to holding data, classes (and structs) can also contain functions! Functions defined inside of a class are called member functions (or sometimes methods). Member functions can be defined inside or outside of the class definition.
It is just called "stateless". Nothing really special about it. Show activity on this post. There is nothing wrong with a class that has no members; controllers do this very frequently.
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 };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With