即使通過明確提的是,在函數指針參數是常量,它似乎並沒有能夠將函數轉換爲這種類型:無法將具有常量參數的函數轉換爲函數指針?
#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編譯器選擇更多細節)。 –