c++ - 鉴于下面的代码片段,我如何确认 v[0] 解析 VS2010 中的 <vector> 头文件的类型?

标签 c++ visual-studio-2010 vector header-files

根据下面的代码,我如何通过头文件确认 v[0] 的类型是 const int&

#include <vector>

int main()
{
    const std::vector<int> v(1);
    decltype(v[0]) b = 1;
}

例如,这就是我在 VS2010 中尝试做的事情:

  1. 将鼠标悬停在上面的 vector 上,我用鼠标右键单击并选择了 Go to definition 我找到了

    template<class _Ty, class _Ax = allocator<_Ty> >
    class vector
        : public _Vector_val<_Ty, _Ax>
    {}
    
  2. 然后我搜索了 operator[] 并找到了 const_reference operator[](size_type _Pos) const

  3. 再次将鼠标悬停在 const-reference 上,我单击鼠标右键并选择 Go to definition 并找到 typedef typename _Alloc::const_reference const_reference;

从现在开始我不知道该去哪里。

最佳答案

你真的不应该使用实现来获取这样的信息。 typedef 链可能很长。而是引用语言标准或 cppreference.com反射(reflect)了标准中的信息。在std::vector的情况下const_reference 被定义为对 value_type 类型常量的引用,它是类型 T(或 _Ty MS 实现)。

*.在 C++11 之前,它被声明为对 Allocator::reference 类型常量的引用

关于c++ - 鉴于下面的代码片段,我如何确认 v[0] 解析 VS2010 中的 <vector> 头文件的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16764909/

相关文章:

c++ - 与 Qt 项目的静态链接

c# - 在 C# 中以编程方式添加没有管理员权限的文件关联

c++ - 使用 std::count 计算字符串 vector 中特定字符的数量 (C++)

c++ - 为什么使用 std::bind() 时会收到 'returning address of local temporary' 警告?

visual-studio-2010 - Cmake 生成不正确的配置

c++ - C++ 中的 vector 到字符串和 HashMap

matlab - 在 Matlab 中转置三角矩阵的列向量?

C++ switch 语句表达式求值保证

c++ - 使用 QtConcurrentRun 和 mutex 的非常简单的方法有时会出现段错误

c++ - 将结构变量与字符串进行比较