I want to develop a template to calculate length of a const char*, char[] without having to redefine the same function.
char[] will implicitly convert to a const char*, so you don't need a template. It is sufficient to write a function that accepts a const char*. Also, such function exists in the standard library so there is no need to write the function except for exercise purposes.
But I got an error, since I should return N class.
Your return statement has the type int, which makes sense for returning a length. But you've declared that the function returns N object instead. This does not make sense for a function that is supposed to return a length. Solution: Declare the function to return an integer type. std::size_t is conventionally used for array / string lengths.
const char*parameter. No need for a template there. There's alsostd::stringandstd::string_view, which have functions to get their length (among many other useful features).int, it doesn't have to return anNjust because it's templated overclass N.stris aconst char*, what should the return type be? Ifstris astd::stringinstance, what should the return type be? Do you see a pattern?