By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 817 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

Restricted friendship

P: n/a
Hello all,

I need an idiom to do the following:

I have a set of non-public member functions in my class. I would like to
grant access to *some* of them to another class. I can't just declare the
other class a friend because that would grant access to *all* member
functions.

Is there any way I can accomplish this?

Thanks,
Dave
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Dave wrote:
I need an idiom to do the following:

I have a set of non-public member functions in my class. I would like to
grant access to *some* of them to another class. I can't just declare the
other class a friend because that would grant access to *all* member
functions.

Is there any way I can accomplish this?


Extract those functions in a base class and grant friendship there.

Why do you need this, BTW?

V
Jul 23 '05 #2

P: n/a
Dave wrote:
I need an idiom to do the following:

I have a set of non-public member functions in my class.
I would like to grant access to *some* of them to another class.
I can't just declare the other class a friend
because that would grant access to *all* member functions.

Is there any way I can accomplish this?

class X {
public:
class Y {
private:
// other private data members
};
private:
// some private data members
Y y;
public:
friend
class Z;
};

class Z has access to some private data members but not others.
Jul 23 '05 #3

P: n/a
"Dave" <be***********@yahoo.com> wrote in message
news:11*************@news.supernews.com...
Hello all,

I need an idiom to do the following:

I have a set of non-public member functions in my class. I would like to
grant access to *some* of them to another class. I can't just declare the
other class a friend because that would grant access to *all* member
functions.

Is there any way I can accomplish this?

Thanks,
Dave

There might be a technical answer to your problem, but I wonder if your
problem doesn't indicate room for design improvement (of course, maybe not).
Specifically, since you identify a method subgroup with some common
properties - the need to grant friendship, it's likely they share other
common properties as well. Perhaps these methods deserve a class of their
own (in which, btw, you could grant access to their friend).
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.