Std :: vector function pointers: different template parameters

Why the next compiler

std::vector<int(*)(double)> func_ptrs; 

But it is not

 std::vector<int(double)> func_ptrs 

?

I get one of these ugly STL error messages in the second case, so I'm not going to post 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) 

C ++ seems to distinguish between int(double) and int (*) (double) . I got the impression that int(*)(double) and int(double) equivalent anyway? Or am I wrong?

I would like to clarify. Thanks in advance.

+5
source share
1 answer

int(double) is actually a function type, not a function pointer. In many cases, it decomposes the function of a pointer, but not here. You cannot use sizeof with a function type, for example - and this is vital for the vector dispenser.

As for your specific error: add_pointer_t<int(double)> (more or less it is used by the vector tetra, internally or directly) int(*)(double) and cannot be increased, since there is no point in performing such an operation.

+6
source

Source: https://habr.com/ru/post/1257904/


All Articles