此问题可能是我误解Objective-C(++)的局限性以及它如何与C++交互的直接结果。或者可能是我错过了在我面前的东西。iOS - GCC无法看到似乎清晰可见的函数
我有一个C++类,在后台执行一些Objective-C++工作。因此,我有一个模板化的C++类,可以调用模板化的函数。然后,我专门为模板创建了一个UIImage。
但是,当我建立我得到以下错误。
../ImageProcessing/ImageProcessing/MacOS/MacOSImage.h:43: error: no matching function for call to 'MacOSImage<R5G5B5A1>::MakeUIImage(std::vector<R5G5B5A1, std::allocator<R5G5B5A1> >&, unsigned int, unsigned int)'
../ImageProcessing/ImageProcessing/MacOS/MacOSImage.h:41: note: candidates are: UIImage* MacOSImage<ColourSpace>::MakeUIImage() [with ColourSpace = R5G5B5A1]
我的头文件是这样的:
#ifndef ImageProcessing_MacOSImage_h
#define ImageProcessing_MacOSImage_h
#include "Image.h"
#ifdef __OBJC__
#import <UIKit/UIImage.h>
#else
typedef void UIImage;
#endif
template< typename ColourSpace > UIImage* MakeUIImage(const std::vector<ColourSpace>& colours, unsigned int width, unsigned int height)
{
return NULL;
}
template< typename ColourSpace > class MacOSImage : public BaseImage<ColourSpace>
{
protected:
public:
MacOSImage(unsigned int width, unsigned int height);
virtual ~MacOSImage() {};
UIImage* MakeUIImage();
};
template< typename ColourSpace > inline MacOSImage<ColourSpace>::MacOSImage(unsigned int width, unsigned int height) :
BaseImage<ColourSpace>(width, height)
{
}
template< typename ColourSpace > inline UIImage* MacOSImage<ColourSpace>::MakeUIImage()
{
return MakeUIImage(BaseImage<ColourSpace>::Pixels(), BaseImage<ColourSpace>::GetWidth(), BaseImage<ColourSpace>::GetHeight());
}
#endif
我发现这个错误,而混乱。尤其是因为如果你忽略了我的特化,那么就有一个模板函数应该与它在文件顶部的原型完全匹配。它唯一的缺点是它会返回NULL。但是,如果我能够编译它,这仍然会给我一个想法。
所以有人有任何想法,为什么这不会编译?
干杯!
编辑:由于这里要求是image.h的:
#ifndef ImageProcessing_Image_h
#define ImageProcessing_Image_h
#include <vector>
template< typename ColourSpace > class BaseImage
{
protected:
unsigned int mWidth;
unsigned int mHeight;
std::vector<ColourSpace> mPixels;
public:
BaseImage(unsigned int width, unsigned int height);
virtual ~BaseImage() {};
std::vector<ColourSpace>& Pixels();
const std::vector<ColourSpace>& Pixels() const;
unsigned int GetWidth() const { return mWidth; }
unsigned int GetHeight() const { return mHeight; }
unsigned int GetBytesPerPixel() const { return sizeof(ColourSpace); }
unsigned int GetBitsPerPixel() const { return GetBytesPerPixel() * 8; }
};
template< typename ColourSpace > inline BaseImage<ColourSpace>::BaseImage(unsigned int width, unsigned int height) :
mWidth(width),
mHeight(height),
mPixels(width * height)
{
}
template< typename ColourSpace > inline std::vector<ColourSpace>& BaseImage<ColourSpace>::Pixels()
{
return mPixels;
}
template< typename ColourSpace > inline const std::vector<ColourSpace>& BaseImage<ColourSpace>::Pixels() const
{
return mPixels;
}
#if defined(_OSX)
#include "MacOS/MacOSImage.h"
#define Image MacOSImage
#elif defined(_WIN32)
#include "Win32/Win32Image.h"
typedef Win32Image Image;
#else
#error We need a platform specific implementation of the image class
#endif
#endif
你有'编译器'(第二个arg)编译错误,而似乎无法在源中找到它 – fazo
std :: vector的std :: allocator是默认初始化,所以你可以忽略AFAIK! – Goz
请问您可以粘贴Image.h的任何相关部分。 – Perception