I only have a passing understanding of templates in C++, but the way I would do it is by making Sum be a template of the matrix type, and the matrix can provide a typedef to access the underlying INT_TYPE.