Compiler Warning (level 1) C4395
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Compiler Warning (level 1) C4395

Error Message

'function' : member function will be invoked on a copy of the initonly data member 'member'

A member function was called on an initonly data member. C4395 warns that the initonly data member cannot be modified by the function.

The following sample generates C4395:

// C4395.cpp
// compile with: /W1 /clr
public value class V {
   V(int data) : m_data(data) {}

   void Mutate() {
      System::Console::WriteLine("Enter Mutate: m_data = {0}", m_data);
      m_data *= 2;
      System::Console::WriteLine("Leave Mutate: m_data = {0}", m_data);

   int m_data;

public ref class R {
   static void f() {
      System::Console::WriteLine("v.m_data = {0}", v.m_data);
      v.Mutate();   // C4395
      System::Console::WriteLine("v.m_data = {0}", v.m_data);

   initonly static V v = V(4);

int main() {
© 2015 Microsoft