// this is the actual template based implementation // of the threshold function. Most of the time, this is a // static hidden function in the C++ file only template void threshold_t(Img &image, T t){ for(int x=0;x t) { image(x,y,c) = 255; }else{ image(x,y,c) = 0; } } } } } // this is the function interface provided within // your library header it switches over the different data types // and calles the worker template. void threshold(ImgBase *image, double t){ switch(image->getDepth()){ case depth8u: threshold_t(*image->asImg(),(icl8u)t); case depth32f: threshold_t(*image->asImg(),(icl32f)t); case ... } }