This class definition should be outside the function I think, along with func2d and others.