Visual Studio 从模板继承时 Intellisense 不工作 class
Visual Studio Intellisense not working when inheriting from template class
这是一个涉及从模板继承的测试片段 classes:
#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()
中,当我尝试使用 this
指针访问间接基 class A<T>
中定义的成员 x
时,x
没有t 出现在 Intellisense 自动完成弹出窗口中。另一方面,直接继承的成员y
确实出现了。
我用 VS2019 和 VSCode+gcc 进行了测试,两者的结果相似。
但我知道 Intellisense 是一个非常强大的引擎,所以我想知道我是否正确地从模板 classes 中继承?如果我错了,正确的方法是什么?
我身边也有同样的情况。我认为这是 C++ Intellisense 的真正问题,而不是 C++ 语法标准.
事实上,项目构建运行良好,可以打印x
的值,没有任何错误,证明问题与[=无关28=]C++语法标准.
而且这只是一个纯C++ IntelliSense问题。并且智能感知无法从二级结构中获取成员。
我有reported the issue on our DC Forum。如果我没有详细描述问题,您可以投票并添加任何评论,这样它会得到更多 Microsoft 的关注。也希望团队能给您一个满意的答复
建议
由于这个过程可能需要很长时间,作为建议,目前也可以让struct C
继承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; }
};
这是一个涉及从模板继承的测试片段 classes:
#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()
中,当我尝试使用 this
指针访问间接基 class A<T>
中定义的成员 x
时,x
没有t 出现在 Intellisense 自动完成弹出窗口中。另一方面,直接继承的成员y
确实出现了。
我用 VS2019 和 VSCode+gcc 进行了测试,两者的结果相似。
但我知道 Intellisense 是一个非常强大的引擎,所以我想知道我是否正确地从模板 classes 中继承?如果我错了,正确的方法是什么?
我身边也有同样的情况。我认为这是 C++ Intellisense 的真正问题,而不是 C++ 语法标准.
事实上,项目构建运行良好,可以打印x
的值,没有任何错误,证明问题与[=无关28=]C++语法标准.
而且这只是一个纯C++ IntelliSense问题。并且智能感知无法从二级结构中获取成员。
我有reported the issue on our DC Forum。如果我没有详细描述问题,您可以投票并添加任何评论,这样它会得到更多 Microsoft 的关注。也希望团队能给您一个满意的答复
建议
由于这个过程可能需要很长时间,作为建议,目前也可以让struct C
继承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; }
};