Download MetaTrader 5

Is it not possible that a function return a object ?

To add comments, please log in or register
Pierre Rougier
390
Pierre Rougier  
Hello,

Is it not possible that a function return a object ?

'return' - structure have objects and cannot be copied OOP_FunctionReturnObject.mq4 27 4

//+------------------------------------------------------------------+
//|                                     OOP_FunctionReturnObject.mq4 |
//|                                         Copyright 2014, Pierre8r |
//|                                              https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, Pierre8r"
#property link      "https://www.mql4.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   CName Martin;
  }
//+------------------------------------------------------------------+
class CName
  {
   // Here is the entire code of the class
  };
//+------------------------------------------------------------------+
CName FunctionReturnObject()
  {
   CName Jacques;
   return(Jacques);
  }
//+------------------------------------------------------------------

Regards,

GreenMoney
379
GreenMoney  
tintin92:
Hello,

Is it not possible that a function return a object ?

'return' - structure have objects and cannot be copied OOP_FunctionReturnObject.mq4 27 4

Regards,


The Return operator "can't return any arrays, class objects, variables of compound structure type"; however, it can return an object pointer.
Pierre Rougier
390
Pierre Rougier  

Hello Thirteen,

Is this correct ?

Should I have to delete the object or is it automatic?


//+------------------------------------------------------------------+
//|                                     OOP_FunctionReturnObject.mq4 |
//|                                         Copyright 2014, Pierre8r |
//|                                              https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, Pierre8r"
#property link      "https://www.mql4.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   CName* Paul;
   Paul= FunctionReturnObject();
  }
//+------------------------------------------------------------------+
class CName
  {
   // Here is the entire code of the class
  };
//+------------------------------------------------------------------+
CName *FunctionReturnObject()
  {
   CName *Jacques=new CName();
   return(Jacques);
  }
//+------------------------------------------------------------------+
Ex Ovo Omnia
3351
Ex Ovo Omnia  
tintin92:

Hello Thirteen,

Is this correct ?

Should I have to delete the object or is it automatic?


Once new is used you have to delete it by delete. Besides, it seem quite ok.

To add comments, please log in or register