Why does the following compile
std::vector<int(*)(double)> func_ptrs;
but this does not
std::vector<int(double)> func_ptrs
?
I get one of those ugly STL error messages in the second case, so I'm not going to put everything here, but at the end of the message I get this
/usr/include/c++/4.8/bits/stl_construct.h:102:30: error: ISO C++ forbids incrementing a pointer of type ‘int (*)(double)’ [-fpermissive]
for (; __first != __last; ++__first)
This seems to imply that C++ cast the type int(double)
to int (*) (double)
. I was under the impression that int(*)(double)
and int(double)
are equivalent anyway? Or am I wrong?
Would like to have some clarification. Thanks in advance.
int(double)
is actually a function type, not a function pointer. It decays to function pointer in many cases, but not here. You can't use sizeof
with a function type, for example - and that's vital for vector
's allocator.
As for your specific error: add_pointer_t<int(double)>
(more or less this is used by vector
's iterator, internally or directly) is int(*)(double)
and cannot be incremented, because it makes no sense to perform such operation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With