readonly (C++)

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

Prohibits assignment to a data member.

  
[readonly]  
  

The readonly C++ attribute has the same functionality as the readonly MIDL attribute.

If you want to prohibit modification of a method parameter, then use the in attribute.

The following code shows a use of the readonly attribute:

// cpp_attr_ref_readonly.cpp  
// compile with: /LD  
[idl_quote("midl_pragma warning(disable:2461)")];  
#include "unknwn.h"  
[module(name="ATLFIRELib")];  
  
[dispinterface, uuid(11111111-1111-1111-1111-111111111111)]  
__interface IFireTabCtrl  
{  
   [readonly, id(1)] int i();  
};  

Attribute Context

Applies toInterface method
RepeatableNo
Required attributesNone
Invalid attributesNone

For more information about the attribute contexts, see Attribute Contexts.

IDL Attributes
Data Member Attributes
Attributes Samples

Show: