ShrimpCrackers
ShrimpCrackers

Reputation: 4542

Getting stack overflow on function call

I have a base class that three classes inherit from. Whenever these child classes are instantiated in a function, I'll get a stack overflow right as the function enters the body. They could be instantiated near the end or the beginning, it doesn't matter. As soon as the function body is entered, I get a stack overflow. If the classes are removed, the function operates normally. The child classes do not contain anything but one overridden function, and their constructors and destructors. The constructors and destructors are all empty.

int main()
{
    Borrow borrow;

    MovieStore store( "STORE!!!!!!" );
    store.initalize();
    store.processTransaction();

    return 0;
}

Not sure how much that would help, but basically borrow is the child class. Once the function body is entered, a stack overflow results. Even if I instantiated it before return 0, it would still crash on entering the function body. If it is removed, program runs normally. I'm actually declaring borrow in a different function (main is just shorter) but it has the same effects whatever function it is placed into.

class Borrow : public Transaction
{
public:
    Borrow();
    virtual ~Borrow();


    virtual void perform( Customer *, Item * );
};

Borrow and the other child classes are the same. Empty constructor and destructor with one overridden virtual function.

The implementation of perform is:

void Borrow::perform( Customer *customer, Item *aMovie )
{
    customer->addMovie( aMovie, "B" );
}

Upvotes: 1

Views: 2723

Answers (2)

ShrimpCrackers
ShrimpCrackers

Reputation: 4542

Thanks to UncleBens, I was able to figure out that a class with a large object was being instantiated multiple times and thus creating a stack overflow.

Upvotes: 1

AlexTheo
AlexTheo

Reputation: 4184

I guess that your function is recursive and you never stop to call it.

Upvotes: 1

Related Questions