Is it not possible that a function return a object ?

 
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,

 
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.
 

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);
  }
//+------------------------------------------------------------------+
 
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.

Reason: