Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2005

Tip: Looking for answers? Try searching our database.

[VS2005] class variable members marked as initonly

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
marco_segurini - 10 Mar 2005 16:06 GMT
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 to inform me that the readonly
class members are not explicitly initialized?

If I translate this program to C# using 'readonly' instead of
'initonly' the compiler returns me a warning for each readonly member
that is not expliciply inizialized.

TIA.
Marco.

///////////////////////////////////////////

#include "stdafx.h"

using namespace System;

ref class Hello
{
};

ref class TestInitOnly
{
public:
  TestInitOnly()
  {
  }

  initonly int i_;
  initonly Hello^ h_;
};

int _tmain()
{
  TestInitOnly^ init = gcnew TestInitOnly();
}
Tomas Restrepo \(MVP\) - 11 Mar 2005 02:28 GMT
Hi Marco,

> The following C++ managed console application compile with no errors
> or warning even if the readonly class members are not explicitly
[quoted text clipped - 6 lines]
> 'initonly' the compiler returns me a warning for each readonly member
> that is not expliciply inizialized.

AFAIK, there's not such a warning currently implemented, and the compiler
will initialize the field to the default value (0/nullptr). You might want
to post a feature request on the msdn feedback center for this!

Signature

Tomas Restrepo
tomasr@mvps.org
http://www.winterdom.com/

ismailp - 13 Mar 2005 18:47 GMT
(no offence) Herb Sutter says, if I recall that, "C++ trusts developer"
:)

Ismail

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.