How can I implement? : if (this == NULL) - page 2

 
Paul Anscombe #:

You are still using NULL so your code is wrong.  

If your code is wrong you will get unpredictable results so just fix the code.

How you declare a pointer variable value with empty/null initialized value?

for example of integer value we can declare like this:

int x = NULL;
int y = EMPTY_VALUE;

then we can check in if statement like this:

if (x == NULL)
{
  // do something
}

if (y == EMPTY_VALUE)
{
  // do something
}

What is the initialized empty/null value for pointer variables like foo?

Note that for pointing to the linked list of pointers, we need to initialize the Head variable with NULL (at first step that there is not any node in list) and, after add first node to the list, the Head variable will point to it.

 
Reza5523 #:

How you declare a pointer variable value with empty/null initialized value?

for example of integer value we can declare like this:

then we can check in if statement like this:

What is the initialized empty/null value for pointer variables like foo?

Note that for pointing to the linked list of pointers, we need to initialize the Head variable with NULL (at first step that there is not any node in list) and, after add first node to the list, the Head variable will point to it.

You don't need to set it to NULL. You can use the same pointer again and again but only once at a time. 

If you want more than one pointer then you need to declare more than one.

Pointers in MQL are only pointers to objects.

You can have an array of them if that helps.

class CTest
{
   public:
   void ShowString(const string Text)
   {
      Print("Text is: " + Text);
   }
};

void OnStart()
{  
   CTest *object;
  
   for(int iC=0; iC<9; iC++)
   {
      object = new CTest;
      object.ShowString("Object-" + iC);
      delete object;
   }
}
class CTest
{
   public:
   void ShowString(const string Text)
   {
      Print("Text is: " + Text);
   }
};

void OnStart()
{
  
   CTest *object[9];
   int iC = 0;

   for(iC=0; iC<9; iC++)
   {
      object[iC] = new CTest;
      object[iC].ShowString("Object-" + iC);
   }

   for(iC=0; iC<9; iC++)
   {
      delete object[iC];
   }
   
}
 

Hm, the array of pointers is good solution instead of linked list of pointers, and I will think about it.

Thanks  Paul Anscombe and everyone :)
 
Reza5523 #:

Hm, the array of pointers is good solution instead of linked list of pointers, and I will think about it.

Thanks  Paul Anscombe and everyone :)

you are welcome

Reason: