cpp implementation of Triangle