custom iterator for a class object