Microsoft KB Archive/820549

= Visibility of unmanaged Visual C++ classes is always set to public =

Article ID: 820549

Article Last Modified on 1/12/2006

-

APPLIES TO


 * Microsoft Visual C++ .NET 2003 Standard Edition

-



SYMPTOMS
When you create an unmanaged class, the Visual C++ .NET 2003 compiler always sets the class visibility to public while generating the assembly. The keyword __nogc on a class indicates that the class is an unmanaged C++ class. If you do not specify __gc or __nogc before the class declaration, the class defaults to __nogc.



CAUSE
The design specifications for Microsoft Visual C++ .NET 2003 indicate that the class visibility is always set to public.



STATUS
This behavior is by design.



Steps to Reproduce the Behavior
  Paste the following code in Notepad:
 * 1) using 

__nogc class Test{};

void main { Test t; }  Save the file as sample.cpp . To create the executable file, run the following command at the Visual Studio .NET command prompt :

cl /clr sample.cpp

 At the Visual Studio .NET 2003 command prompt, run the following command to run the MSIL disassembler to view the sample.exe assembly:

ildasm sample.exe

  Verify that the declaration for the Test class is public. The declaration should appear as follows: .class value public sequential ansi sealed </ol>

Note The Microsoft Visual C++ .NET 2002 compiler sets the visibility of unmanaged classes to private.

Keywords: kbprogramming kbprb kbcompiler KB820549

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.