Here is the relevant code from the full listing:
#include "CImg.h"
using namespace cimg_library;
int main() {
CImg<unsigned char> src("Tulips.jpg");
int width = src.width();
int height = src.height();
int depth = src.depth();
//New grayscale images.
CImg<unsigned char> gray1(width,height,depth,1);
CImg<unsigned char> gray2(width,height,depth,1);
// ...
(src,gray1,gray2).display("RGB to Grayscale");
}
How does the line (src,gray1,gray2).display("RGB to Grayscale"); work? How is the display member function applied to each of the objects in the comma-separated list?
CImgoverloadsoperator,which returns aCImgListobject which is a list containing the twoCImgobjects given as operands. That object also overloadsoperator,to allowCImgobjects to be added to the list.The expression
(src,gray1,gray2)is equivalent to((src,gray1),gray2). The inner set of parentheses,(src,gray1), create theCImgList, and then(...,gray2)appendsgray2to that list, returning a reference to the same list.CImgListhas the member functiondisplay.