implicit enum conversion - enum to int

 

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

 
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;

 
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

 

Thanks a lot! This helped me too!

Regards!

Bruno 

 
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
 
Thank you for your post even though its old it still hold meaning
 
Thank you very much! Me helped too.
Reason: