Udostępnij za pomocą


Błąd kompilatora C3145

"object" : zmienna globalna lub statyczna może nie mieć zarządzanego lub typu WinRT "type"

Uwagi

Obiekty CLR lub WinRT można definiować tylko w zakresie funkcji.

Przykłady

Poniższy przykład generuje kod C3145 i pokazuje, jak go naprawić:

// C3145.cpp
// compile with: /clr
using namespace System;
ref class G {};

G ^ ptr;   // C3145
G ^ ptr2 = gcnew G;   // C3145

ref class GlobalObjects {
public:
   static G ^ ptr;   // OK
   static G ^ ptr2 = gcnew G;   // OK
};

int main() {
   G ^ ptr;   // OK
   G ^ ptr2 = gcnew G;   // OK
}

Poniższy przykład generuje kod C3145:

// C3145b.cpp
// compile with: /clr
ref class MyClass {
public:
   static int data;
};

interior_ptr<int> p = &(MyClass::data);   // C3145

void Test(interior_ptr<int> x) {}

int main() {
   MyClass ^ h_MyClass = gcnew MyClass;
   interior_ptr<int> p = &(h_MyClass->data);
}