将未匹配的int.size分配给一维浮点向量

问题描述

我是编程方面的新手,我的问题对您来说可能微不足道。我做了很多尝试,但无法弄清楚为什么该程序没有给我一个错误。这段代码是我一直在做的练习之一。这里的部分代码是将向量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;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)