I need a quick sanity check, can I copy struct like on the example below?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
struct MyStruct
{
int a{ 0 };
float b{ 0 };
bool c{ 0 };
};
MyStruct EvaluateResult()
{
MyStruct result;
return result;
}
bool MyFunction(MyStruct* result)
{
*result = EvaluateResult(); // Is it OK to copy struct that way?
result->c = false;
}
So my thinking is that I am dereferencing pointer to struct and do implicit copy assignment. Is this correct?
The thing is that I have a C# code that is consuming MyFunction (from DLL) and sometimes result->c is returned as true on the C# side. So I am starting to think that maybe I am messing up with the pointer by doing *result = EvaluateResult(), because if I comment out this line, result->c is always false.