[英]MQL4: Object = (Class*)NULL;
I came across this in a program I am trying to improve. 我在尝试改进的程序中遇到了这个问题。
class Class1
{
private:
public:
Class1();
~Class1();
protected:
Class2* Object2;
};
Imbalance::Imbalance()
{
Object2 = (Class2*)NULL;
}
Can someone tell me what the * means when you create the object and why when instantiating the class you would make the object = the class something null. 有人可以告诉我*在创建对象时是什么意思,为什么在实例化类时将使对象=该类为空。 Is there a book I can read on this?
我有一本书可以阅读吗? Or any good document or webpage on class and objects in MQL4, C++ ...
或关于MQL4,C ++中的类和对象的任何好的文档或网页...
The *
in C++ mean it's a pointer to an object. C ++中的
*
表示它是指向对象的指针。
Initializing a pointer to NULL
means that it's pointing to nowhere ( by the way nullptr
would be a better alternative nowadays ). 初始化一个指向
NULL
的指针意味着它指向无处(顺便说一下,现在nullptr
将是一个更好的选择)。
Usually, at a moment in your code, you'll find some statement like: 通常,在代码中的某个时刻,您会发现一些语句,例如:
if ( Object2 == NULL ) // if not pointing to an object
Object2 = new Class2; // create a new one
Most books on C++ explain pointers in depth. 关于C ++的大多数书籍都对指针进行了深入的解释。
So my first answer would be "The C++ programming language" from B.Stroustrup. 因此,我的第一个答案是B.Stroustrup的“ C ++编程语言”。
Some online tutorials: here and here . 一些在线教程: 此处和此处 。
Edit: MQL4 language 编辑:MQL4语言
In MQL4 language, which was historically based on a C-like syntax constructs and recent (post Build 509 ) extensions brought some more ( borrowed from MQL5 domain ), the *
is also a pointer to an object, and new
creates an object dynamically. 在MQL4语言中,它过去一直基于类似C的语法构造,并且最近的扩展(后Build 509)带来了更多的扩展(从MQL5域借来的),
*
也是指向对象的指针,而new
动态地创建了一个对象。 But unlike C++, it's not a direct pointer to a memory place, but an indirect pointer using the concept of a descriptor . 但是,与C ++不同,它不是指向内存位置的直接指针,而是使用描述符概念的间接指针。
A predefined constant variable NULL
means -- like in C++ -- that there is no value. 像C ++中一样,预定义的常量变量
NULL
表示没有值。 It can be assigned to variables of any other fundamental types without conversion. 可以将其分配给任何其他基本类型的变量,而无需进行转换。 The comparison of fundamental type variables with the
NULL
value is allowed. 允许将基本类型变量与
NULL
值进行比较。
In "New-MQL4" ( post Build 509 ) NULL
can also be compared to pointers to objects created with the new
operator. 在“ New-MQL4”(内部版本509)中,也可以将
NULL
与使用new
运算符创建的对象的指针进行比较。
(Thanks to user3666197 for the additional MQL4 specific info) (感谢user3666197提供额外的MQL4特定信息)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.