I have just started learning c++, and I found an strange behavior while assigning vector size to int.
When I do like below, Then there is no warning
int removeElement(vector<int> &nums)
{
const int len = nums.size();
}
But when I write code like this, then it gives me warning
warning: narrowing conversion of '(& nums)->std::vector<int>::size()'
from 'std::vector<int>::size_type' {aka 'long long unsigned int'} to
'int' inside { } [-Wnarrowing]
The erroneous code:
int removeElement(vector<int> &nums)
{
const int len { nums.size() };
}
I want to understand, why there is no warning in first case?