【发布时间】:2021-01-26 04:31:54
【问题描述】:
我是一个完全的编程新手,我的问题对你来说可能完全是微不足道的。我尝试了很多,但无法弄清楚为什么这个程序没有给我错误。这段代码是我一直在做的练习之一。这里的部分代码是将向量vec1中的行数分配给变量rows
当我将unsigned int(带有.size())分配给一维浮点向量时,它应该会给我一个错误,对吧?该练习正在使用此代码并且运行良好。我想知道我错过了什么。
// Example program
#include <iostream>
#include <vector>
int main()
{
//declaring a float 1D vector
std::vector<float> vec1(4,0);
//declaring new variable 'row' - Type float - 1D vector
std::vector<float>::size_type rows;
rows = vec1.size(); // this should give me error because i am assigning a unsigned int(with .size()) to row - 'float 1d vector'.
std::cout<<rows<<std::endl;
}
【问题讨论】:
-
std::vector<float>::size_type不是向量,是std::vector::size返回的类型
标签: c++ vector stdvector unsigned-integer size-type