I bug in the for each loop statement?

G

Guest

Is this a bug in the for each loop or am I coding something wrong (or is this
how its suppose to function and I don't understand how an array property and
the for each interact [this is always a possibility :)]

The commented out code is the problem area as it generates the error:
->for each statement cannot operate on variables of type 'overloaded-function'

using namespace System;

ref class ArrayProp
{
public:
ArrayProp(int size)
{
numArray = gcnew array<int>(size);
}

property array<int>^ NumArray
{
array<int>^ get()
{
return numArray;
}

void set ( array<int>^ value )
{
numArray = value;
}
}
private:
array<int>^ numArray;
};

void main()
{
ArrayProp aprop(5);

for ( int i = 0 ; i < aprop.NumArray->Count ; ++i )
aprop.NumArray = i;

for ( int i = 0 ; i < aprop.NumArray->Count ; ++i )
Console::WriteLine(aprop.NumArray);

// for each (int i in aprop.NumArray)
// {
// Console::WriteLine(i);
// }
}
 
B

Ben Schwehn

Hello Stephen,

there are more appropiate groups on privatenews.microsoft.com for the VS
8 Beta.
Is this a bug in the for each loop or am I coding something wrong (or is this
how its suppose to function and I don't understand how an array property and
the for each interact [this is always a possibility :)] [...]
// for each (int i in aprop.NumArray)
// {
// Console::WriteLine(i);
// }
}


this looks (didn't actually test it) like the bug described here
http://blogs.msdn.com/arich/. So it's a compiler bug, nothing you're
doing wrong.

Workaround is to explicitly call the property accessor.

hth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top