Download MetaTrader 5

Is it not possible that a function return a object ?

To add comments, please log in or register
Having difficulties in understanding the Trading Signals service? Read the article!
Pierre Rougier
390
Pierre Rougier 2014.02.28 20:39 
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 2014.02.28 21:12  
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 2014.02.28 22:09  

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
3155
Ex Ovo Omnia 2014.02.28 22:41  
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