What good ways?

B

bobsled

What're good ways to pass a pointer or reference of "client" though
pureAbstractBaseClass() so that both derive1 and derive2 can access
client::clientMethod()? Thanks for your comments!

class client
{
public:
void clientMethod();
};

class pureAbstractBaseClass
{
public:
// All pure virtual functions here
};

class derive1 : public pureAbstractBaseClass
{
....
public:
void use_client_method() { // call client::clientMethod() here }
....
};

class derive2 : public pureAbstractBaseClass
{
....
public:
void use_client_method() { // call client::clientMethod() here }
....
};
 
R

Rolf Magnus

bobsled said:
What're good ways to pass a pointer or reference of "client" though
pureAbstractBaseClass() so that both derive1 and derive2 can access
client::clientMethod()? Thanks for your comments!

I don't fully understand your question. Do you want to know how th pass
a reference to your member function or do you want to know how to store
a reference in an object? Or maybe something else?
 
D

Daniel T.

bobsled said:
What're good ways to pass a pointer or reference of "client" though
pureAbstractBaseClass() so that both derive1 and derive2 can access
client::clientMethod()? Thanks for your comments!

class client
{
public:
void clientMethod();
};

class pureAbstractBaseClass
{
public:
// All pure virtual functions here
};

class derive1 : public pureAbstractBaseClass
{
...
public:
void use_client_method() { // call client::clientMethod() here }
...
};

class derive2 : public pureAbstractBaseClass
{
...
public:
void use_client_method() { // call client::clientMethod() here }
...
};

One way:

class derive1: public pureAbstractBaseClass, private client
{
public:
void use_client_method() { clientMethod(); }
};

Another way:

class derive2: public pureAbstractBaseClass
{
client c;
public:
void use_client_method() { c.clientMethod(); }
};

I prefer the latter myself...
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top