473,379 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Restricted friendship

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
3 1401
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Marcin Vorbrodt | last post by:
Is friendship inherited? Meaning if: class Base { public: friend FriendClass; }; class Derived : public Base { }
7
by: Erik | last post by:
private and protected members can only be accessed by deriving a class or by giving friendship. The problem with friendship is that friend statements are written inside the class. A FriendShip...
4
by: JH Trauntvein | last post by:
Consider the following example: namespace n1 { class cn1_base; namespace n1_helpers { class helper1 {
4
by: Mr Dyl | last post by:
I'm trying to declare the following friendship and VS.Net 2003 is complaining: template <class T> class Outter { class Inner {...} ... }
3
by: tom.s.smith | last post by:
I know that friendship isn't inherited in C++, and have two questions. (1) Why? Is it a technical problem, or just by design? If the latter, isn't this a little prescriptive, and shouldn't there...
2
by: Mark P | last post by:
Is there a way to do anything like the following: class A { friend void B::foo(); ... }; class B
4
by: werasm | last post by:
I've read the following somewhere: "Friendship is the strongest form of coupling there is. That is, you introduce a high degree of dependency when you declare a friend, since the friend becomes...
6
by: Hicham Mouline | last post by:
Hello, A semi-skeptical colleague is asking me why friendship is not inheritable, specifically: class Base { public: virtual void f() const =0; }; class Derived : public Base {
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.