Re: [Dev-C++] segmentation fault at runtime
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2004-12-15 21:55:34
|
Wait a minute.
m_pSrv is a pointer pointing to an object.
KviIrcServer* beConsole::server()
should return a pointer, i.e. the contents of m_pSrv, i.e.
return m_pSrv;
and not a copy of an object as is done by
return *m_pSrv;
When a function returns a pointer, this of course doesn't mean that it
returns the address of the pointer, but the value stored in the pointer,
i.e. the address of an object.
/Per W
On Wed, 15 Dec 2004, Black Eagle wrote:
> It's tricky but I think I got it
>
> In fact I am returning a pointer to m_pSrv which is a pointer itself, rat=
her
> than the adress of the class, right ?
>
> What could have worked is if m_pSrv was the class and that I returned &m_=
pSrv,
> the adress of the class.
>
> But I've done like this :
> KviIrcServer beConsole::server()
> {
> =09qDebug("returning server");
> =09return *m_pSrv;
> }
>
> Thanks for help !
>
> Le mercredi 15 D=E9cembre 2004 22:06, Alfred P. Reaud a =E9crit :
> > Hi Black Eagle,
> >
> > It could be that you are returning the address of m_pSrv rather than it=
's
> > contents. You've declared m_pSrv as a pointer to a KviIrcServer class.
> > However, in server(), you return m_pSrv, rather than it's contents *m_p=
Srv.
> > server() is declared as returning a pointer to the class, which is the
> > value of m_pSrv, not it's address.
> >
> > Hope that makes sense!
> >
> > Black Eagle <bla...@ea...> wrote:
> >
> > Hi guys!
> >
> > I got a problem at run time, when using a pointer in a function.
> >
> > The error is in the function KviIrcServer* server() at line : return
> > m_pSrv;
> >
> > In all other functions I got no problem with this variable. It is anoth=
er
> > class that tries to call this function, it's the friendclass beChannel
> >
> >
> > <snip>
> > class KviIrcServer;
> > <snip>
> > KviIrcServer* server();
> > <snip>
> > private :
> > KviIrcServer * m_pSrv;
> > <snip>
> > KviIrcServer* beConsole::server()
> > {
> > qDebug("returning server");
> > return m_pSrv;
> > }
> > <snip>
> >
> >
> >
> >
> > Alfred P. Reaud
>
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://productguide.itmanagersjournal.com/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|