Download MetaTrader 5

(bug?) static struct::factory not working

To add comments, please log in or register
Launch your trading signal and add account monitoring!
dck
70
dck 2012.07.05 15:43 

While trying to realize factories within Structs I came across something that's possibly a Bug.
It compiles fine, but a static Method seems to return the wrong thing...

simplified example:

struct Info
{
   double a;
   double b;
   double c;
   
                     Info() : a(1.1), b(2.2), c(3.3)                          {}
                     Info(double a, double b, double c) : a(a), b(b), c(c)    {}
   
   Info              TestFactory(const double a, const double b, const double c) const;
   static Info       StaticFactory(const double a, const double b, const double c);
};

Info Info::TestFactory(const double a, const double b, const double c) const
{
   Info result(a, b, c);
   return result; 
}

static Info Info::StaticFactory(const double a, const double b, const double c)
{
   Info result(a, b, c);
   return result; 
}

void OnStart()
{
   Info info1, info2, info3;
   
   info2 = info1.TestFactory(4.4, 5.5, 6.6);
   info3 = Info::StaticFactory(7.7, 8.8, 9.9);

   Print(info1.a); // Prints 1.1 OK!
   Print(info2.a); // Prints 4.4 OK!
   Print(info3.a); // Prints 1.1 ERROR! should be 7.7

}

The static Factory returns an Info struct initialized with the standard constructor, ignoring the parameters ???

Is this a Bug or me doing something wrong?

regards
Daniel 

Documentation on MQL5: Language Basics / Object-Oriented Programming / Static Members of a Class
  • www.mql5.com
Language Basics / Object-Oriented Programming / Static Members of a Class - Documentation on MQL5
dck
70
dck 2012.07.06 07:24  

The TestFactory Method works well, but I still can't return an Info Struct from the StaticFactory with its properties set right.

Ilyas
1206
Ilyas 2012.07.06 12:14  
Thank you for message. It looks like a bug, we will check it.
dck
70
dck 2012.07.06 15:57  
Thank you for your support, hope you can fix it!
Ilyas
1206
Ilyas 2012.07.10 11:17  
Fixed, please wait for updates.
To add comments, please log in or register