473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Initonly - but it is not (bug?) VC++ 2008/CLR

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

Oct 21 '08 #1
2 1196
Armin Zingler wrote:
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?
You're right, it appears to be a bug. The workaround is quite simple
(introduce a temporary thus):

List<TVB^>^ It = f->Items;

It[0]->s = gcnew IO::MemoryStream();
Or what I would actually recommend is making that member use stack
semantics.
>
(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

Oct 21 '08 #2
"Ben Voigt [C++ MVP]" <rb*@nospam.nospamschrieb
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?

You're right, it appears to be a bug. The workaround is quite
simple (introduce a temporary thus):

List<TVB^>^ It = f->Items;

It[0]->s = gcnew IO::MemoryStream();
Or what I would actually recommend is making that member use stack
semantics.
Sorry for the late answer and thanks for your reply. I'll file a bug report
@ MSFT connect.
Armin

Oct 23 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
by: Maxim Yegorushkin | last post by:
The following code: #include <iostream> class base { private: virtual ~base() { std::cout << "virtual ~base()\n";
2
by: marco_segurini | last post by:
Hi, The following C++ managed console application compile with no errors or warning even if the readonly class members are not explicitly initialized. Is there any way to force the compiler...
6
by: Felix I. Wyss | last post by:
It appears that VC++2003 has a code generator bug related to template parameters that are a pointer-to-member type: If the actual template argument is a virtual method, VC generates code that...
1
by: Robert Ludewig | last post by:
I have sucessfully imported and compiled a complex MFC 6.0 project from vc++6.0 (MFC6.0) into vc++ 8.0 (MFC 8.0). It contains several subprojects (libs and dlls). In vc++ 6.0 those project linked...
16
by: Edward Diener | last post by:
After spending more than a day reducing a complicated compiler bug to a simple case I reported it to the MSDN Product Feedback Center as a bug just now. However this bug is completely stymying my...
1
by: Peter Oliphant | last post by:
I have written a program using VC++ 2008 Express (Beta 2). It uses System::Speech for speech recognition. My program works fine in VS GUI, both Debug and Release. It also works fine in Debug...
12
by: lee.crabtree | last post by:
In C#, an array marked 'readonly', as in: public readonly bool array = new bool; would allow individual members of the array to be modified while protecting the array reference itself from...
2
by: NvrBst | last post by:
I'm not too much of a C++ programmer but I have a bunch of C programs (they compile with GNU) and want to get them to compile in VC++ 2008. In Unix I go "./configure" and it makes a "Makefile". ...
2
by: goo.one1 | last post by:
Hi All, I'm looking for info on how to port VC++ 6 code/projects to VC++ 9 (2008). I noticed that there is a converter built-in for Visual *BASIC* to convert from VS6 to 9... I have found...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.