This problem is not what you need in programming. You must not allow cyclic dependency of a parameter on another. Break the dependency i.e. don't couple them or watch carefully where one is expected to exit a loop. Look at this site http://stackoverflow.com/questions/2143327/c-template-parameter-cyclic-dependency