Visual C++ .NET/Class/literal

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

literal string initializer

<source lang="csharp">

  1. 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();

}

 </source>


static vs literal

<source lang="csharp">

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

}

 </source>