473,508 Members | 2,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function / Method in class

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
Jan 30 '06 #1
12 1587
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-lit...t.html#faq-5.8.

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

Stephan

Jan 30 '06 #2
On Mon, 30 Jan 2006 11:14:04 +0200, "Riaan" <ri***@c-pos.co.za> 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 ??


Show us the code.

--
Bob Hairgrove
No**********@Home.com
Jan 30 '06 #3
Hi Stephan,

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

--
Riaan Bekker
Odyssey Software

"Stephan Brönnimann" <br****@hotmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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-lit...t.html#faq-5.8.

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

Stephan

Jan 30 '06 #4
On Mon, 30 Jan 2006 12:04:11 +0200, "Riaan" <ri***@c-pos.co.za> wrote:

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.:
//************
//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:
//***************
//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
No**********@Home.com
Jan 30 '06 #5
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
Jan 31 '06 #6
Hi Bob,

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

--
Riaan Bekker
Jan 31 '06 #7
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 ?
Jan 31 '06 #8
On Tue, 31 Jan 2006 09:22:56 +0200, "Riaan" <ri***@c-pos.co.za> wrote:
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
No**********@Home.com
Jan 31 '06 #9
On Tue, 31 Jan 2006 09:23:56 +0200, "Riaan" <ri***@c-pos.co.za> wrote:
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-lit...tore-mgmt.html

--
Bob Hairgrove
No**********@Home.com
Jan 31 '06 #10
On Tue, 31 Jan 2006 09:43:36 +0200, "Riaan" <ri***@c-pos.co.za> wrote:
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
No**********@Home.com
Jan 31 '06 #11
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
Feb 4 '06 #12
On Wed, 1 Feb 2006 14:13:53 +0200, "Riaan" <ri***@c-pos.co.za> wrote:
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
No**********@Home.com
Feb 4 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
9577
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
3
3028
by: Robert | last post by:
Python doesn't know the class of a method when container not direct class attribute: >>> class X: .... def f():pass .... g=f .... l= .... >>> X.g <unbound method X.f>
9
2743
by: Lenard Lindstrom | last post by:
I was wondering if anyone has suggested having Python determine a method's kind from its first parameter. 'self' is a de facto reserved word; 'cls' is a good indicator of a class method ( __new__...
3
1700
by: Gregory Bond | last post by:
I'm building a class hierarchy that needs to keep as a class variable a reference to a (non-member) function, so that different subclasses can use different generator functions. But it seems...
10
7274
by: Martin Vorbrodt | last post by:
Example code in one of my books intrigues me: class B { public: B* Clone() const { B* p = DoClone(); assert(typeid(*p) == typeid(*this)); return p; }
2
2497
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a...
17
2211
by: Eric Brunel | last post by:
Hi all, I just stepped on a thing that I can't explain. Here is some code showing the problem: ----------------------------- class C: f = None def __init__(self): if self.f is not None:
11
3395
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the...
27
1696
by: idoerg | last post by:
Hi all, I am running Python 2.5 on Feisty Ubuntu. I came across some code that is substantially slower when in a method than in a function. ################# START SOURCE ############# # The...
8
1515
by: Viktor | last post by:
Can somebody give me an explanation what happened here (or point me to some docs)? Code: HMMM = None def w(fn): print 'fn:', id(fn) HMMM = fn
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7132
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.