求教MT5返回结构体的函数为什么会报错?

Jing Yang  

请教大家为什么在mql5中为什么不能编译通过 ,代码在以前是可以用的,2年没用了,最近空闲想学习再修改的时候发现不能编译了

class CProgram 

  {

   struct myStruct

     {
      long              position_id;
      ulong             ticket;
      double            profit_point;
      double            profit;  
     };

   
   public :
  myStruct DelaPositionIdByData(long tick_id);

  };
  
myStruct CProgram::DelaPositionIdByData(long tick_id)

  {
   myStruct myDealTick;
   return myDealTick;


  }


下面是报错信息:

'myStruct' - unexpected token, probably type is missing? mProgram.mqh 19 1

'CProgram' - semicolon expected mProgram.mqh 19 10

'return' - expressions are not allowed on a global scope mProgram.mqh 23 4

'}' - expressions are not allowed on a global scope mProgram.mqh 26 3







Ziheng Zhuang  

把结构体的定义放在外面


struct myStruct
{
   long              position_id;
   ulong             ticket;
   double            profit_point;
   double            profit;
};

class CProgram
{

public :
   myStruct DelaPositionIdByData(long tick_id);

};
myStruct CProgram::DelaPositionIdByData(long tick_id)
{
   myStruct myDealTick;
   return myDealTick;

}
原因: