当我使用以下代码执行1秒的某些操作时,我从Visual Studio收到C4101警告:警告C4101:'highResClock':未引用的局部变量.我不明白为什么我在声明它后使用highResClock两次时会收到此警告.
chrono::high_resolution_clock highResClock;
chrono::duration<int, ratio<1, 1> > dur(1);
chrono::time_point<chrono::high_resolution_clock> end = highResClock.now() + dur;
while (highResClock.now() < end)
{
// do something repeatedly for 1 second
}
Run Code Online (Sandbox Code Playgroud)
编辑:看起来Visual Studio的警告是因为std :: chrono :: high_resolution_clock :: now()是一个静态函数.访问now()不需要highResClock变量,即使这是我选择使用的特定方法.Visual Studio似乎将此解释为不使用变量.当我使用以下内容时,我不再收到任何警告:
chrono::duration<int, ratio<1, 1> > dur(1);
chrono::time_point<chrono::high_resolution_clock> end = chrono::high_resolution_clock::now() + dur;
while (chrono::high_resolution_clock::now() < end)
{
// do nothing
}
Run Code Online (Sandbox Code Playgroud)