C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Function / Method in class

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Riaan
Guest





PostPosted: Mon Jan 30, 2006 10:00 am    Post subject: Function / Method in class Reply with quote



Hi Everybody,

I created my own class with 2 methods (both public) in it. When I use the 1
method it works fine, as soon as I make a call to the other method, the
program crashes. I removed all code from the second method already, also
removed all variables passed to it.. what can it be ??

--
Riaan Bekker
Back to top
Stephan Brönnimann
Guest





PostPosted: Mon Jan 30, 2006 10:00 am    Post subject: Re: Function / Method in class Reply with quote



Riaan wrote:
Quote:
Hi Everybody,

I created my own class with 2 methods (both public) in it. When I use the 1
method it works fine, as soon as I make a call to the other method, the
program crashes. I removed all code from the second method already, also
removed all variables passed to it.. what can it be ??

--
Riaan Bekker

You should post a minium compileable code sample, see
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8.

My best guess: you've used different versions of the class' header
file.

Stephan
Back to top
Bob Hairgrove
Guest





PostPosted: Mon Jan 30, 2006 10:00 am    Post subject: Re: Function / Method in class Reply with quote



On Mon, 30 Jan 2006 11:14:04 +0200, "Riaan" <riaan@c-pos.co.za> wrote:

Quote:
Hi Everybody,

I created my own class with 2 methods (both public) in it. When I use the 1
method it works fine, as soon as I make a call to the other method, the
program crashes. I removed all code from the second method already, also
removed all variables passed to it.. what can it be ??

Show us the code.

--
Bob Hairgrove
NoSpamPlease (AT) Home (DOT) com
Back to top
Riaan
Guest





PostPosted: Mon Jan 30, 2006 11:00 am    Post subject: Re: Function / Method in class Reply with quote

Hi Stephan,

thanks man, you gave me an idea and I had a look at the created DLL.. it was
a different version !! Smile THANKS MAN

--
Riaan Bekker
Odyssey Software

"Stephan Brönnimann" <broeni (AT) hotmail (DOT) com> wrote in message
news:1138614337.399970.21120 (AT) g14g2000cwa (DOT) googlegroups.com...
Quote:
Riaan wrote:
Hi Everybody,

I created my own class with 2 methods (both public) in it. When I use the
1
method it works fine, as soon as I make a call to the other method, the
program crashes. I removed all code from the second method already, also
removed all variables passed to it.. what can it be ??

--
Riaan Bekker

You should post a minium compileable code sample, see
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8.

My best guess: you've used different versions of the class' header
file.

Stephan
Back to top
Bob Hairgrove
Guest





PostPosted: Mon Jan 30, 2006 1:00 pm    Post subject: Re: Function / Method in class Reply with quote

On Mon, 30 Jan 2006 12:04:11 +0200, "Riaan" <riaan@c-pos.co.za> wrote:

Quote:

Here is the code !

The functions I am talking about is LogEvent (not working) and ShowEvents(
working )


OK, I see that you seem to have gotten it to work...however, some
comments are in order:

(1) You need a virtual destructor in EventsInterface if you are ever
going to delete a derived class through a pointer to EventsInterface.

(2) In this code, you should remove the unnecessary semicolons after
inline definitions, e.g.:

Quote:
//************
//Login Plugin
class LoginInterface
{
public:
virtual ~LoginInterface() {};
// ^ no semicolon here
virtual void ShowLogin(void) const = 0;
// ^ semicolon is necessary
};

(3) I believe you must also provide an empty definition for the
destructor here in addition to making it pure virtual:

Quote:
//***************
//Database Plugin
class ConnInterface
{
public:
virtual ~ConnInterface() = 0;

};

// e.g., somewhere outside of the above declaration:
ConnInterface::~ConnInterface() {}

(4) Here's a serious bug: It seems that Events::fileControl doesn't
get initialized until Events::LoadPlugins is called. But if "plugin"
isn't properly initialized (line 197 in the function's body),
fileControl is also not initialized. However, the destructor of Events
deletes fileControl. You need to initialize fileControl to 0 in your
constructor, also in case an exception occurs. Since you have more
than one pointer member in the class, it would also be a good idea to
use smart pointers instead of plain pointers -- this is especially
important WRT exception safety.

(5) There is no exception handling anywhere. Have you thought about
this at all yet?

Since I haven't ever done any Qt development, I obviously cannot hope
to compile the code, so I didn't look at the rest.

--
Bob Hairgrove
NoSpamPlease (AT) Home (DOT) com
Back to top
Riaan
Guest





PostPosted: Tue Jan 31, 2006 8:00 am    Post subject: Re: Function / Method in class Reply with quote

Hi Bob,

I would like to know what do you mean by using SMART pointers instead of
normal pointers ?

--
Riaan Bekker
Back to top
Riaan
Guest





PostPosted: Tue Jan 31, 2006 8:00 am    Post subject: Re: Function / Method in class Reply with quote

Hi Bob,

Thank you very much for the comments, I do appreciate it much. Would you
please give me an example of the kind of exception handling that I can add
to the program ?

Regards,

--
Riaan Bekker
Back to top
Riaan
Guest





PostPosted: Tue Jan 31, 2006 8:00 am    Post subject: Re: Function / Method in class Reply with quote

Bob,

As soon as I set my fileControl to 0 in my class constructor the program
already gives an exception error.
fileControl = 0;

In what other way can I init the fileControl plug-in ?
Back to top
Bob Hairgrove
Guest





PostPosted: Tue Jan 31, 2006 10:00 am    Post subject: Re: Function / Method in class Reply with quote

On Tue, 31 Jan 2006 09:22:56 +0200, "Riaan" <riaan@c-pos.co.za> wrote:

Quote:
Hi Bob,

Thank you very much for the comments, I do appreciate it much. Would you
please give me an example of the kind of exception handling that I can add
to the program ?

Regards,

http://www.parashift.com/c++-faq-lite/exceptions.html

--
Bob Hairgrove
NoSpamPlease (AT) Home (DOT) com
Back to top
Bob Hairgrove
Guest





PostPosted: Tue Jan 31, 2006 11:00 am    Post subject: Re: Function / Method in class Reply with quote

On Tue, 31 Jan 2006 09:23:56 +0200, "Riaan" <riaan@c-pos.co.za> wrote:

Quote:
Hi Bob,

I would like to know what do you mean by using SMART pointers instead of
normal pointers ?

http://www.parashift.com/c++-faq-lite/freestore-mgmt.html

--
Bob Hairgrove
NoSpamPlease (AT) Home (DOT) com
Back to top
Bob Hairgrove
Guest





PostPosted: Tue Jan 31, 2006 11:00 am    Post subject: Re: Function / Method in class Reply with quote

On Tue, 31 Jan 2006 09:43:36 +0200, "Riaan" <riaan@c-pos.co.za> wrote:

Quote:
Bob,

As soon as I set my fileControl to 0 in my class constructor the program
already gives an exception error.
fileControl = 0;

In what other way can I init the fileControl plug-in ?


Have you tried this?

Events::Events()
: fileControl(0)
{
// etc.
};

--
Bob Hairgrove
NoSpamPlease (AT) Home (DOT) com
Back to top
Riaan
Guest





PostPosted: Wed Feb 01, 2006 5:13 pm    Post subject: Re: Function / Method in class Reply with quote

Bob,

I tried Events::Events() : fileControl(0) but it still crashes on the first
use of the fileControl (obviously, because the object is not created).
If I want to create an exception handler in my constructor, to check if the
fileControl object was created, how will I halt the usage of the Event
class. Without the fileControl object the event class can not continue with
its functionality

Regards
--
Riaan Bekker
Back to top
Bob Hairgrove
Guest





PostPosted: Sat Feb 04, 2006 12:00 pm    Post subject: Re: Function / Method in class Reply with quote

On Wed, 1 Feb 2006 14:13:53 +0200, "Riaan" <riaan@c-pos.co.za> wrote:

Quote:
Bob,

I tried Events::Events() : fileControl(0) but it still crashes on the first
use of the fileControl (obviously, because the object is not created).
If I want to create an exception handler in my constructor, to check if the
fileControl object was created, how will I halt the usage of the Event
class. Without the fileControl object the event class can not continue with
its functionality

But you didn't create fileControl in your constructor ... you did it
later in a separate function (forgot which one)??

If you initialize the pointer to 0 as I showed you (i.e. in the
constructor's initialization list), then call some other function from
the body of the constructor to set its value, you can check it after
the function returns to see if it is still zero. If it is still 0,
then I would throw an exception from the constructor's body which will
cause the creation of that particular instance of Events to fail.
Otherwise, you risk having a fully-created object which has no
fileControl which could be used by mistake.

Check out the FAQ on exceptions and exception handling ... just use
the links I gave you previously and search for it.

--
Bob Hairgrove
NoSpamPlease (AT) Home (DOT) com
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.