Search code examples
c++classrecursionconstructorfunction-calls

Is it a considered a recursive function if I have an overloaded function that calls one of its other instances?


This is hypothetical, but I have a class with two, overloaded constructors - none of which are the default constructors. If I were to call one constructor from the other, would it be recursive? Example:

class Example
{
     Example(const int integer)
     {
          //Constructor Code Here
     }

     Example(argument)
     {
          Example object(68);
          //Rest of constructor code
     }
};

Solution

  • No

    Recursion is when a function calls itself, not an overloaded function of the same name with different parameters. What you are describing is not recursion at all. It is delegating constructors, a new feature introduced in C++11. And by definition: "Delegating constructors cannot be recursive".