p is a list of integers.
std::list<int> p;
if ( 2 % p(0) == 0 );
But p has "expression must have integral or unscoped enum type" error.
Why?
p is a list of integers.
std::list<int> p;
if ( 2 % p(0) == 0 );
But p has "expression must have integral or unscoped enum type" error.
Why?
list
doesn't overload operator(int)
, this is a requirement for you to be able to say p(0)
.
If you meant p[0]
, list
doesn't overload operator[int]
either, this is only for vector
, map
(or actually operator[keyType]
), etc. This is because list
s don't have random access (meaning you can't get any element, unless you loop through)
You can however do something like:
if (2 % p.front() == 0)
or
if (2 % *p.begin() == 0)
which accesses the first element.