calling base class function only once

F

Furqan

Hi,

Consider the following class hierarchy:

A
B C D

a has a fcuntion func() which needs to be called only once during
application lifetime.

B b;
b.func();


.......



later

C c;
c.func(); //should nt get called or executed.

How can this be done?

One way is to use a mutex and initialize the first time func is called.

Is there any other way?Some design pattern?

Regards,
Furqan
 
A

Alf P. Steinbach

* Furqan:
Hi,

Consider the following class hierarchy:

A
B C D

a has a fcuntion func() which needs to be called only once during
application lifetime.

Do it in the Z constructor and make Z a singleton.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top