A
Armin Zingler
Hi,
could anyone please tell me why I get a compile error (C3893) in the last
line? Error message is (translated):
"'Frame::Items': The usage of the L value of an initonly data member is only
allowed in an instance constructor of the Frame class."
using namespace System;
using namespace System::Collections::Generic;
public ref class TVB abstract
{
public:
IO::Stream^ s;
};
public ref class Frame
{
public:
initonly List<TVB^>^ Items;
Frame(): Items(gcnew List<TVB^>){};
};
int main()
{
Frame^ f = gcnew Frame();
f->Items[0]->s = gcnew IO::MemoryStream(); //<<<<<<<< C3893
};
The point is, I do _not_ assign anything to f->Items. I assign something to
a member of an Item of the list. The member is _not_ initonly. Therefore, I
don't see a reason for the error. If I split the line up in two lines -
which shouldn't make any difference in this case - it does work:
TVB^ tmp = f->Items[0];
tmp->s = gcnew System::IO::MemoryStream();
Is this a bug or do I overlook anything?
(I do know that the code wouldn't work because I wouldn't have added
anything to the generic list, but even if I did it doesn't compile...)
Armin
could anyone please tell me why I get a compile error (C3893) in the last
line? Error message is (translated):
"'Frame::Items': The usage of the L value of an initonly data member is only
allowed in an instance constructor of the Frame class."
using namespace System;
using namespace System::Collections::Generic;
public ref class TVB abstract
{
public:
IO::Stream^ s;
};
public ref class Frame
{
public:
initonly List<TVB^>^ Items;
Frame(): Items(gcnew List<TVB^>){};
};
int main()
{
Frame^ f = gcnew Frame();
f->Items[0]->s = gcnew IO::MemoryStream(); //<<<<<<<< C3893
};
The point is, I do _not_ assign anything to f->Items. I assign something to
a member of an Item of the list. The member is _not_ initonly. Therefore, I
don't see a reason for the error. If I split the line up in two lines -
which shouldn't make any difference in this case - it does work:
TVB^ tmp = f->Items[0];
tmp->s = gcnew System::IO::MemoryStream();
Is this a bug or do I overlook anything?
(I do know that the code wouldn't work because I wouldn't have added
anything to the generic list, but even if I did it doesn't compile...)
Armin