Rosh,
There's some problem with functions that returns struct.
The compilation goes with no error, but the code simply doesn't run, no error alert of any kind, the code simply does nothing.
I created a code demo to show you. (I would put this in the Service Desk instead of here, but I havent' enough rate to post there this bug).
Please help.
//-----------------------------------------------------
struct Info
{
double propA;
double propB;
double propC;
};
void OnStart()
{
Info info;
info = Dummy();
Print(info.propA);
Print(info.propB);
Print(info.propC);
}
Info Dummy()
{
Info result;
result.propA = 1.1;
result.propB = 2.2;
result.propC = 3.3;
return result;
}
//-----------------------------------------------------
This isn't a bug - it would happen in any C++ code. The problem is that Info result only exists during the life of the Dummy function call.
You could code it like this
struct Info { double propA; double propB; double propC; }; void OnStart() { Info info; Dummy(info); Print(info.propA); Print(info.propB); Print(info.propC); } void Dummy(Info& inoutInfo) { inoutInfo.propA = 1.1; inoutInfo.propB = 2.2; inoutInfo.propC = 3.3; }
Paul
Rosh,
There's some problem with functions that returns struct.
The compilation goes with no error, but the code simply doesn't run, no error alert of any kind, the code simply does nothing.
It is not allowed to return neither a structure or a class from function. You can pass your structure into function as parameter and set it's needed properties or you can return class object pointer (structures don't have a pointers).
See sample which Paul provided.
It is not allowed to return neither a structure or a class from function. You can pass your structure into function as parameter and set it's needed properties or you can return class object pointer (structures don't have a pointers).
How have you run your sample - on usual way into terminal or in debug way from editor?
Rosh,
I had tested the code in debug way only.
On usual way, I have tested now and there's no problem, the code runs corretly. Thanks.
Any way, could you please ask the development team to fix it in the debug mode.
Thanks !!!
This isn't a bug - it would happen in any C++ code. The problem is that Info result only exists during the life of the Dummy function call.
You could code it like this
Paul
Paul,
It's an good alternative way to make this code work, thanks.
But in fact, the code should work (and works on not debug mode).
You are right, it is a bug. I will fix it.
Bug fixed, please wait for updates.
Paul,
It's an good alternative way to make this code work, thanks.
But in fact, the code should work (and works on not debug mode).
My apologies - learn something every day, as they say. This syntax is a carryover from C and in checking further I see that it is valid C/C++.
Paul
This isn't a bug - it would happen in any C++ code. The problem is that Info result only exists during the life of the Dummy function call.
You could code it like this
Paul
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Rosh,
There's some problem with functions that returns struct.
The compilation goes with no error, but the code simply doesn't run, no error alert of any kind, the code simply does nothing.
I created a code demo to show you. (I would put this in the Service Desk instead of here, but I havent' enough rate to post there this bug).
Please help.
//-----------------------------------------------------
struct Info
{
double propA;
double propB;
double propC;
};
void OnStart()
{
Info info;
info = Dummy();
Print(info.propA);
Print(info.propB);
Print(info.propC);
}
Info Dummy()
{
Info result;
result.propA = 1.1;
result.propB = 2.2;
result.propC = 3.3;
return result;
}
//-----------------------------------------------------