从模板类继承时,Visual Studio Intellisense 不起作用

莱昂·克鲁兹

这是一个涉及从模板类继承的测试片段:

#include <iostream>
using namespace std;

template <typename T>
struct A {
    T x;
};

template <typename T>
struct B : public A<T> {
    B(T x, T y) : A<T>{ x }, y{ y } { }
    T y;
};

template <typename T>
struct C : public B<T> {
    C(T x, T y, T z) : B<T>{ x, y }, z{ z } { }
    T z;

    // when I typed `this->`, Intellisense didn't give me the option `x`,
    // which is iherited from `A<T>` and should appear in the autocomplete pop-up.
    // In contrast, `this->` did give the option `y`.
    void test() { cout << this->x << ", " << this->y << ", " << z << endl; }
};

int main() {
    C<int> c{ 1, 2, 3 };
    c.test();  // prints out `1, 2, 3` as expected
    return 0;
}

代码编译并运行。但是void C<T>::test(),当我尝试使用指针访问x在间接基类中定义的成员时没有出现在 Intellisense 自动完成弹出窗口中。另一方面,直接继承的成员确实出现了。A<T>thisxy

我用 VS2019 和 VSCode+gcc 进行了测试,两者都给出了相似的结果。

但我知道 Intellisense 是一个非常强大的引擎,所以我想知道我是否正确地从模板类继承?如果我错了,正确的方法是什么?

Perry Qian-MSFT

我身边也有同样的情况。而且我认为这是C++ Intellisense而不是C++ 语法标准的真正问题

事实上,该项目构建运行良好,可以打印出 的值,x没有任何错误,证明问题与C++语法标准无关

它只是一个纯 C++ IntelliSense 问题。并且 Intellisense 无法从二级结构中获取成员。

我已经在我们的 DC 论坛上报告了这个问题如果我没有详细描述问题,您可以投票并添加任何评论,以便它得到更多微软的关注。我希望团队会给你一个满意的答复。

建议

由于该过程可能需要很长时间,作为建议,到目前为止,您还可以让 struct Cinherit A到目前为止Intellisense无法从A(二级结构)中获取成员

template <typename T>
struct C : public B<T>, public A<T> {
    C(T x, T y, T z) : B<T>{ x, y }, z{ z } { }
    T z;

    // when I typed `this->`, Intellisense didn't give me the option `x`,
    // which is iherited from `A<T>` and should appear in the autocomplete pop-up.
    // In contrast, `this->` did give the option `y`.
    void test() { cout <<this->x << ", " << this->y << ", " << z << endl; }
};

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

UnityEngine 的 Visual Studio Intellisense 不起作用

Intellisense在Visual Studio Code中不起作用-mssql扩展

JavaScript Intellisense在Visual Studio 2015中不起作用

Razor intellisense在Visual Studio 2012中不起作用

Visual Studio Code - Emmet / Intellisense 自动完成似乎在属性内不起作用

DirectX Visual Studio 模板不起作用

Visual Studio交互命令不起作用

Visual Studio 的 clickonce 更新不起作用

Greenshot在Visual Studio中不起作用

Visual Studio VSIX OnSolutionOpened 不起作用

C ++模板功能在Visual Studio中不起作用

Visual Studio 2015 RC3 TypeScript Intellisense不再起作用

Visual Studio Intellisense不显示某些类

Visual Studio sizeof()差异IntelliSense与编译时

编写JavaScript时缺少Visual Studio的IntelliSense

Intellisense不起作用的golang测试文件

IntelliSense数据绑定不起作用

Intellisense在聚合中不起作用

在Visual Studio 2017中,“使干净”的任务配置不起作用

Javascript 导入在 Visual Studio 代码中不起作用

参考在Visual Studio 2015中不起作用

Visual Studio 2019 构建顺序不起作用

Visual Studio(.exe)导出不起作用

C ++ #include在Microsoft Visual Studio 2010中不起作用

onbeforeunload在Visual Studio 2013中不起作用

函数open()在Visual Studio Code中不起作用

通过在C#/ Visual Studio 2012中不起作用

参考在 Visual Studio 2017 中不起作用

Visual Studio 2022 System.Environment.GetEnvironmentVariable 不起作用