c++ - Visual Studio 智能感知错误

标签 c++ visual-studio visual-c++ intellisense

template <typename T>
class Test {
        friend Test<T> & operator * (T lhs, const Test<T> & rhs) {
            Test<T> r(rhs);
//              return r *= lhs;
        }
}

4 IntelliSense: identifier "T" is undefined

为什么 T 定义在第 3 行而不是第 4 行?我的意思是我想这不是一个真正的错误只是一个智能感知错误......无论如何它都有效但是有什么不对吗?我可以修好吗?或者以某种方式删除红色波浪线?

我用的是visual studio 2010,不知道其他版本会不会出现这种情况?

最佳答案

智能感知显示 T未定义,因为它是通用模板类型。根据您实例化类的方式,T将是不同的类型。例如,如果您有 Test<int> A , T类型为 int , 但如果你调用 Test<string> A , T类型为 string对于那个类及其方法。

关于c++ - Visual Studio 智能感知错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1726104/

相关文章:

c++ - v8 hello world 示例链接错误

c++ - 如何从中心找到旋转矩形的顶点?

c++ - VS2010 "Framework and References"与 "Linker > Input"

c++ - 类/函数模板组合的意外诊断

visual-studio-2008 - 带有 OpenSSL 的 Axis2C - 没有 OPENSSL_APPLINK 错误

c++ - 如何从文件中只读取一行

c++ - 这不是我要求的输出

c++ - 这个错误是什么意思 : variable-size type declared outside of any function

c# - 如何轻松地从编译中排除某些代码行?

c++ - SSE half loads (_mm_loadh_pi/_mm_loadl_pi) 发出警告