David Wilson
David Wilson

Reputation: 43

Does this qualify as recursion?

I am aware that a function calling itself is recursive. But, is an object creating objects of it's own type recursive? Additionally, I have no intention of using this code as it will quite obviously cause problems, I'm only interested in whether or not it qualifies as recursion.

class Cell 
{
    Cell()
    {
        Cell c = new Cell();
    }
} 

Upvotes: 3

Views: 98

Answers (1)

Bathsheba
Bathsheba

Reputation: 234685

Indeed it does. The Cell constructor will be called by itself, assuming that some calling code sets off the construction of a Cell instance.

Unless you block the recursion somehow (perhaps with a maximum instance limit), your program will eventually crash.

Upvotes: 3

Related Questions