I cant understand this error in using structure

Back to topics list To post a new topic, please log in or register
avatar
52
renzbub 2016.01.30 14:24
 

In the following code i always see error     'MqlDateTime' - struct or class already defined 

I cant see why? 

struct MqlDateTime
{ 
   int year;           // Year 
   int mon;            // Month 
   int day;            // Day 
   int hour;           // Hour 
   int min;            // Minutes 
   int sec;            // Seconds 
   int day_of_week;    // Day of week (0-Sunday, 1-Monday, ... ,6-Saturday) 
   int day_of_year;    // Day number of the year (January 1st is assigned the number value of zero)  
};

void OnInit()   
{ 
MqlDateTime time;

int day = time.day;
int hour = time.hour;
int dayOfWeek =  time.day_of_week;
struct MqlDateTime
avatar
108
eddie 2016.01.30 14:44 #
 

What do you think "already defind" means?

Select the Statement and press "F1".


avatar
52
renzbub 2016.01.30 20:31 #
 
eddie:

What do you think "already defind" means?

Select the Statement and press "F1".


I see that already defined means I have declared MqlDateTime as a struct data type and so I cant declare it again. But, how come for example in the following code i can assign a struct data type as tradeSettings and then define this object as trade which then allows me to access the member variable of the structure

 to create the slippage object. But, in the above code it doesn't let me define a new object as time using the declared MqlDateTime object? I've taken this all from the MQL4 reference and doesn't appear to work for me.

void OnInit()   
{
struct tradeSettings
{   
   ulong slippage;
   double price;
   double stopLoss;
   double takeProfit;
   string comment;
};       

tradeSettings trade;
ulong slippage = trade.slippage = 50;

Print(slippage);  

 

avatar
12985
WHRoeder 2016.01.30 20:35 #
 
renzbub: I have declared MqlDateTime as a struct data type and so I cant declare it again.
Wrong, you have declared it as a struct; that is the second declaration. Compare your code with the example MqlDateTime - MQL4 Documentation
Back to topics list  

To add comments, please log in or register