Other Uses of gcroot and autogcroot

The templates gcroot and auto_gcroot can also be used in two other scenarios. Just as it is illegal to use tracking handles for data members of native classes, it is also forbidden to define global variables of a tracking handle type. The same restriction applies to static variables of managed functions. The following code shows these restrictions:

FileSystemWatcherA fsw; // error: "global variable may not have managed type"

static FileSystemWatcherA fsw = gcnew FileSystemWatcher(); // error: "static variable may not have managed type"

Was this article helpful?

0 0

Post a comment