You have already defined GP to return a type of "pet" and now you are redefining it to return a type of "dog". That's not allowed.
Pet is a base class. Pet is, by its nature, an abstract type (you cannot own a pet of type "pet"; you own a "dog" or a "goldfish"). Therefore, pet should be an abstract base class. But it isn't. You have provided implementations for functions that should not have any.
I would argue that GP should not exist at all. GP seems to be a factory function; why not just use a constructor?
your right it didn't cross my mind , but know i remembered ,
cause in template functions you can choose to vary between the function variables but not the return type .
as a result you can't define a function with two different return types .