VS2017 编译代码语法不正确,缺少 Intellisense
VS2017 compiles code that is syntactically incorrect, Intellisence missing
我从 VS2017 working won C++ 项目中得到了这个奇怪的行为:
缺少智能 - 我只是键入没有警告的纯文本,它仍然可以编译:
整个文件没有错误。但是,当我在此函数范围之外的任何地方尝试相同的操作时,一切都按预期工作:
问题出现在我的泛型函数实现中:
#pragma region Public API
template <typename Key, typename Value>
void BinarySearchTree<Key, Value> ::Put(Key key, Value val)
{
Node node = root_;
if(node.key == null)
sadadasd
affsa
dasds
dasdsad
asdsad
}
#pragma endregion
Class 定义如下:
template <typename Key, typename Value>
class BinarySearchTree {};
再次,它是死寂 - 根本没有 red/yellow。编译后的代码甚至可以运行。就好像那部分被注释掉了一样。
尝试重新加载 VS,没有帮助
在您使用带有参数的模板之前,它不会被实例化,因此它不会存在,因此不会有错误。
模板仅在实例化时编译为二进制文件。不用模板,代码就扔了
Class template instantiation A class template by itself is not a type,
or an object, or any other entity. No code is generated from a source
file that contains only template definitions. In order for any code to
appear, a template must be instantiated: the template arguments must
be provided so that the compiler can generate an actual class (or
function, from a function template).
根据 class template 参考:
A class template by itself is not a type, or an object, or any other
entity. No code is generated from a source file that contains only
template definitions. In order for any code to appear, a template must
be instantiated...
更新:这似乎是特定于 Visual C++ 的错误。其他编译器可能会报错。
Trivial example for GCC
此 SO post 中有关该主题的更多信息:
What exactly is "broken" with Microsoft Visual C++'s two-phase template instantiation?
这是 Visual C++ 的已知问题,已存在很长时间。它不实现两阶段查找。它基本上只是完全跳过模板,直到它们被实例化。显然,他们最终修复了它(至少部分修复了)。
https://blogs.msdn.microsoft.com/vcblog/2017/09/11/two-phase-name-lookup-support-comes-to-msvc/
我从 VS2017 working won C++ 项目中得到了这个奇怪的行为: 缺少智能 - 我只是键入没有警告的纯文本,它仍然可以编译:
整个文件没有错误。但是,当我在此函数范围之外的任何地方尝试相同的操作时,一切都按预期工作:
问题出现在我的泛型函数实现中:
#pragma region Public API
template <typename Key, typename Value>
void BinarySearchTree<Key, Value> ::Put(Key key, Value val)
{
Node node = root_;
if(node.key == null)
sadadasd
affsa
dasds
dasdsad
asdsad
}
#pragma endregion
Class 定义如下:
template <typename Key, typename Value>
class BinarySearchTree {};
再次,它是死寂 - 根本没有 red/yellow。编译后的代码甚至可以运行。就好像那部分被注释掉了一样。
尝试重新加载 VS,没有帮助
在您使用带有参数的模板之前,它不会被实例化,因此它不会存在,因此不会有错误。
模板仅在实例化时编译为二进制文件。不用模板,代码就扔了
Class template instantiation A class template by itself is not a type, or an object, or any other entity. No code is generated from a source file that contains only template definitions. In order for any code to appear, a template must be instantiated: the template arguments must be provided so that the compiler can generate an actual class (or function, from a function template).
根据 class template 参考:
A class template by itself is not a type, or an object, or any other entity. No code is generated from a source file that contains only template definitions. In order for any code to appear, a template must be instantiated...
更新:这似乎是特定于 Visual C++ 的错误。其他编译器可能会报错。
Trivial example for GCC
此 SO post 中有关该主题的更多信息:
What exactly is "broken" with Microsoft Visual C++'s two-phase template instantiation?
这是 Visual C++ 的已知问题,已存在很长时间。它不实现两阶段查找。它基本上只是完全跳过模板,直到它们被实例化。显然,他们最终修复了它(至少部分修复了)。
https://blogs.msdn.microsoft.com/vcblog/2017/09/11/two-phase-name-lookup-support-comes-to-msvc/