Visibility of unmanaged Visual C++ classes is always set to public (820549)



The information in this article applies to:

  • Microsoft Visual C++ .NET (2003)

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.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Paste the following code in Notepad:
    #using <mscorlib.dll>
    
    __nogc class Test{};
    
    void main()
    {
      Test t;
    }
    
  2. Save the file as sample.cpp .
  3. To create the executable file, run the following command at the Visual Studio .NET command prompt :

    cl /clr sample.cpp

  4. 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

  5. Verify that the declaration for the Test class is public. The declaration should appear as follows:
    .class value public sequential ansi sealed
Note The Microsoft Visual C++ .NET 2002 compiler sets the visibility of unmanaged classes to private.

Modification Type:MinorLast Reviewed:1/12/2006
Keywords:kbProgramming kbCompiler kbprb KB820549 kbAudDeveloper kbAudITPRO