无法完成操作 'Create Declaration / Definition':代码元素是只读的

The operation 'Create Declaration / Definition' could not be completed: code element is read only

我正在 Visual Studio 2015 年在 Win10 64 位上使用 CMake 构建系统开发一个 C++ 项目。

我曾经通过单击 header 中的声明然后 Quick Actions and Refactorings->Create Declaration / Definition.

在 C++ 文件中创建函数定义

出于某种原因,此功能不再适用于我的项目。每当我尝试使用 "Create Definition" 时,我都会收到此错误消息:

The operation 'Create Declaration / Definition' could not be completed for the following reason:

Add/Remove operation is impossible, because the code element 'NameOfClass' is read only

此外,当我选择 Quick Actions and Refactorings 时,小弹出窗口 window 只显示两个选项:

当此功能起作用时,VS 通常会显示 window 和四个选项,如下所示:

我知道在 SO 上有很多类似的问题,但是 none 似乎解决了这个特定的错误。到目前为止,我已经尝试了所有建议:

None这个有什么影响

这个功能很棒,问题很烦人。如果有人有任何线索,请帮助。

好吧,我的错。我在 CMake 脚本中有一个错误,这就是为什么一些头文件没有包含在 Visual Studio 项目中的原因。如果出现此错误,请确保将 .cpp.hpp 文件都添加到您的 VS 项目文件中。