可能noob问题。我希望使用CImg库来进行一些图像处理。他们中的一些可能是(8位)类型和其中一些(16位)。不幸的是,我不知道数据的类型,直到用户不选择文件来处理。当然,我可以这样做:模板。没有类型在编译期间知道
...
CImg <unsigned char> img_unisgned_char;
CImg <unsigned short> img_unisgned_short;
...
if (user_pick_8bit) img_unisgned_char.load_raw(fname,img_size_x,img_size_y);
if (user_pick_16bit) img_unisgned_short.load_raw(fname,img_size_x,img_size_y);
...
但CIMG方法99%,看起来完全为“无符号的字符”,“诠释”或“浮动”类型相同(如“load_raw”或“模糊”例如)。有什么办法可以做 - 我不知道 - 指针? - 因此,当用户选择文件我可以创造奇迹,如:
if (user_pick_8_bit) img = img_unisgned_char;
if (user_pick_16bit) img = img_unisgned_short;
...
//now no mother of what type is picked up by user I simply make:
img.load_raw(...);
相关问题:[http://stackoverflow.com/q/608409/501250](http://stackoverflow.com/q/608409/501250)。如果您无法使用虚拟基类对CImg <>'进行翻新,则可能不适用您的情况。 – cdhowie 2013-04-10 19:47:05
在我的网页搜索期间,我找到了这个解决方案。但是我不明白我如何在我的情况下使用它。 (我对C++的了解甚至不足以改变CIMg库中的任何东西......)。所以我唯一的选择是为每种类型创建单独的代码? – user2267612 2013-04-10 19:54:58
不一定。你可以定义你自己的模板函数:'template void do_image_processing(/ * ... * /){CImg img; img.load_raw(/ * ... * /); }' –
cdhowie
2013-04-10 19:56:38