Visual C++ .NET/Class/literal
literal string initializer
#include "stdafx.h"
using namespace System;
ref class MyClass
{
literal String^ name = "Bob";
public:
MyClass()
{
Console::WriteLine(name);
}
void Print()
{
Console::WriteLine(name);
}
};
int main()
{
MyClass^ c = gcnew MyClass();
c->Print();
}
static vs literal
#include "stdafx.h"
public ref class MyClass
{
public:
static const int i = 15;
literal int j = 25;
};
template<int i>
void f()
{ }
int main()
{
//int a1[MyClass::i]; // error: static const MyClass::i isn"t considered a constant
int a2[MyClass::j]; // OK
//f<MyClass::i>(); // error
f<MyClass::j>(); // OK
}