我想在垃圾收集类中保留一个静态计数器,并使用Interlocked :: Increment递增它.这样做的C++/CLI语法是什么?
我一直在尝试以下变化,但到目前为止没有运气:
ref class Foo
{
static __int64 _counter;
__int64 Next()
{
return System::Threading::Interlocked::Increment( &_counter );
}
};
Run Code Online (Sandbox Code Playgroud)
你需要使用一个跟踪参考你的_int64
值,使用%跟踪参考符号:
ref class Bar
{
static __int64 _counter;
__int64 Next()
{
__int64 %trackRefCounter = _counter;
return System::Threading::Interlocked::Increment(trackRefCounter);
}
};
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1957 次 |
最近记录: |