Compiler Error C3891

 

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

The latest version of this topic can be found at Compiler Error C3891.

var' : a literal data member cannot be used as a l-value

A literal variable is const, and its value cannot be changed after it is initialized in the declaration.

The following sample generates C3891:

// C3891.cpp  
// compile with: /clr  
ref struct Y1 {  
   literal int staticConst = 9;  
};  
  
int main() {  
   Y1::staticConst = 0;   // C3891  
}  

Show: