D
David Lowndes
The following example illustrates something that's taken me a while to
suss out (debugging someone else's code )...
The crux is that the code compiles cleanly at W4, and the issue is
that I'm passing a property by reference to a function that's trying
to modify it.
Needless to say the result isn't what was intended as the property
doesn't get modified.
So... ought the compiler to allow this?
At the very least I'd hope to have a warning message.
#include "stdafx.h"
using namespace System;
ref struct MyStruct
{
int m_i1;
property int m_i2;
};
void f1( int % i )
{
i++;
}
int main(array<System::String ^> ^/*args*/)
{
MyStruct s;
s.m_i1 = 1;
s.m_i2 = 2;
Console::WriteLine(L"m_i1 is:" + s.m_i1.ToString() + " m_i2
is: " + s.m_i2.ToString() );
f1( s.m_i1 );
f1( s.m_i2 );
Console::WriteLine(L"m_i1 is:" + s.m_i1.ToString() + " m_i2
is: " + s.m_i2.ToString() );
return 0;
}
Dave Lowndes
suss out (debugging someone else's code )...
The crux is that the code compiles cleanly at W4, and the issue is
that I'm passing a property by reference to a function that's trying
to modify it.
Needless to say the result isn't what was intended as the property
doesn't get modified.
So... ought the compiler to allow this?
At the very least I'd hope to have a warning message.
#include "stdafx.h"
using namespace System;
ref struct MyStruct
{
int m_i1;
property int m_i2;
};
void f1( int % i )
{
i++;
}
int main(array<System::String ^> ^/*args*/)
{
MyStruct s;
s.m_i1 = 1;
s.m_i2 = 2;
Console::WriteLine(L"m_i1 is:" + s.m_i1.ToString() + " m_i2
is: " + s.m_i2.ToString() );
f1( s.m_i1 );
f1( s.m_i2 );
Console::WriteLine(L"m_i1 is:" + s.m_i1.ToString() + " m_i2
is: " + s.m_i2.ToString() );
return 0;
}
Dave Lowndes