I've been recently trying out C++11, specifically the auto keyword, which turned out to be quiet interesting and useful.
However, for some reason it doesn't work with initialization list of pointers to functions. Firstly I looked for the answer in my book and I found that "auto keyword only works for single initialization values and not for initialization lists", but when I've tried:
auto foo = { "bar", "bar", "bar" };
std::cout << *(foo.begin());
it worked just fine, but when I try to do that:
// bar is a simple void bar() function
auto foo = { bar, bar, bar };
Visual Studio compiler spits:
error C1001: An internal error has occurred in the compiler.
While that works:
auto foo = bar;
Therefore I have decided to make a little trip over the internet to get more information about std::initializer_list and there I have learned that it's actually quite similar to std::vector. So, why wouldn't I try it?
std::vector<void (*)()> foo = { bar, bar, bar };
(*foo.begin())();
Work flawlessly. Since then I'm stuck and I have no idea why auto keyword doesn't work with initialization list of pointers to functions. Why does it have problems particularly with pointers to functions and what is most important does C++ standard say anything about it?
EDIT:
I've also tried the same thing using GCC and yup, it works and therefore it looks like you guys are right that MSVC compiler has a bug. I guess I'll need to wait until they fix it and in meantime I'll be simply using GCC.
It seems that it is simply a bug of MS VC++. At least this code
auto foo = { bar, bar, bar };
where bar is some function is compiled successfully with GCC.
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