Hi, I get a segfault when I try to instantiate a class I wrote. I don't know what the problem is here. The constructor is never entered.

Details:

/* Connection.h: */
class Stream
{
    private:
        ACE_Message_Queue<CONNECTION_SYNCH> *serverq;
        Provider                            *provider;
        ACE_Event_Handler                   *serverp;

    public:
        Stream(ACE_Message_Queue<CONNECTION_SYNCH>*, Provider*, ACE_Event_Handler*);

        ULONG send(char*, size_t);
        ULONG printf(char*, ...);
        ULONG close(void);
};

#include "Connection.cpp"

/* Connection.cpp: */

Stream::Stream(ACE_Message_Queue<CONNECTION_SYNCH> *q, Provider *p, ACE_Event_Handler *h)
{
    printf("MAKING A STREAM!!!\n");

    this->serverq = q;
    this->provider = p;
    this->serverp = h;
}

ULONG Stream::send(char *buf, size_t len)
{
    /* ... */
}

ULONG Stream::printf(char *frm, ...)
{
    /* ... */
}

ULONG Stream::close()
{
    /* ... */
}

And here, I'm trying to instantiate it:

ACE_Message_Queue<CONNECTION_SYNCH> *q = this->msg_queue();
        printf("ACE_Message_Queue<CONNECTION_SYNCH> *q = %p\n", q);
        ACE_Reactor *reac = this->reactor();
        printf("ACE_Reactor *reac = %p\n", reac);
        printf("ClientService *this = %p\n", this);

        Stream stream(q, reac, this);

        printf("MADE THE STREAM!!! SEE CONSTRUCTOR CALL ^?\n");

        this->descr->dispatch(buf, sizeof(buf), &stream);
        return 0;

Here's the actual output:

ACE_Message_Queue<CONNECTION_SYNCH> *q = 4bae8
ACE_Reactor *reac = 3f430
ClientService *this = 4ba70
Segmentation Fault (core dumped)

-- So "MAKING A STREAM!!!\n" from Stream::Stream is never printed. I'm stumped here. Please help

Man that was dumb! it was calling the class printf.... I had an infinite recursion

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.