即使通过明确提的是,在函数指针参数是常量,它似乎并没有能够将函数转换为这种类型:无法将具有常量参数的函数转换为函数指针?
#include <iostream>
template <typename T>
class Image{};
template <typename TPixel>
static void
FillImage(const Image<TPixel>* const image){}
//FillImage(Image<TPixel>* const image){} // Replacing the above line with this one compiles fine
int main()
{
typedef Image<float> ImageType;
ImageType* image = new ImageType;
void (*autoFunctionPointer)(const decltype(image)) = FillImage;
autoFunctionPointer(image);
}
谁能解释如何使它做到这一点的转换?
您错过了一个'const',目前参数扩展为'ImageType * const'。你不能通过'decltype'轻松搞定。 – Xeo
如果你正在使用C++ 11,为什么不只是'auto'? – leftaroundabout
@leftaroundabout - 我指定我想使用的过载(见http://stackoverflow.com/questions/13632507/how-to-get-a-function-pointer-to-the-overloaded-function-that编译器选择更多细节)。 –