implicit enum conversion - enum to int

Back to topics list To post a new topic, please log in or register
avatar
58
Chistabo 2015.05.14 16:52
 

Hi!

I want to explicitly convert 'enum' type into 'int' type.

// --- global variables ---
enum TRADE_TYPE{DontTradeType,TradeType,BuyOnlyType,SellOnlyType};TRADE_TYPE Trade_type;
// then I pass 'Trade_type' into function call - SetBtnText(setSparam, Trade_type);
// --- TRADE BUTTON TOGGLE --------------------------------------------------------------------------------
void TradeBtnToggle(long chartID,string sparam)
  {
   long setChartID=chartID;
   string setSparam=sparam;
   switch(Trade_type)
     {
      case DontTradeType:
        {
         Trade=true;BuyOnly=false;SellOnly=false;Trade_type=TradeType;SetBtnText(setSparam,Trade_type);break;
         Print("-TradeBtnToggleF()- setSparam= "+setSparam); // test
        }
    ...
}}
// --- SET BUTTON TEXT AND COLOR --------------------------------------------------------------------------
void SetBtnText(string setSparam, int value)
  {
   string btnTxtSparam=setSparam;
   if(btnTxtSparam=="Trade_btn")
     {
     Trade_type=value; // Trade_type=(int)value - 'implicit...' warning
      Print("-SetBtnTextF()- btnTxtSparam= "+btnTxtSparam+" - value= "+value); // test
     }
  }

As written above in the code, Trade_type=(int)value is still producing 'implicit enum conversion' warning. The code compiles OK, since by default 'enum' type is integer (int?), and the Print returns i.e.

2015.05.14 16:47:36.893    MovChi EA EURAUD,H1: -SetBtnTextF()- btnTxtSparam= Trade_btn - value= 1.

For the sake of learning to better understand coding and for the sake of minimizing warnings, please help me resolve this issue.

Thank you,

Best regards,


Simon

S love nia


avatar
1109
Ovo 2015.05.14 17:04 #
 
Chistabo:

Hi!

I want to explicitly convert 'enum' type into 'int' type.

As written above in the code, Trade_type=(int)value is still producing 'implicit enum conversion' warning. The code compiles OK, since by default 'enum' type is integer (int?), and the Print returns i.e.

2015.05.14 16:47:36.893    MovChi EA EURAUD,H1: -SetBtnTextF()- btnTxtSparam= Trade_btn - value= 1.

For the sake of learning to better understand coding and for the sake of minimizing warnings, please help me resolve this issue.

Thank you,

Best regards,


Simon

S love nia


It used to default to the int type, but it does not any longer.  Correct casting is

 Trade_type=(TRADE_TYPE)value;

avatar
58
Chistabo 2015.05.14 18:43 #
 
Ovo:

It used to default to the int type, but it does not any longer.  Correct casting is

 Trade_type=(TRADE_TYPE)value;

Ovo, you are DaMan! It works like a charm. Thank you very mucho!

Best regards,


Simon

S love nia

avatar
9
Leovader 2016.08.25 10:08 #
 

Thanks a lot! This helped me too!

Regards!

Bruno 

avatar
12985
WHRoeder 2016.08.25 15:24 #
 
Ovo: It used to default to the int type, but it does not any longer. Correct casting is Trade_type=(TRADE_TYPE)value;
Exactly. Perhaps Chistabo and Leovader should read the manual: Typecasting of Numeric Types
Back to topics list  

To add comments, please log in or register