473,396 Members | 2,085 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,396 software developers and data experts.

Friend Class

Hi,

I am writing an application with a large number of various classes, and
I want some of them to have Friend access to protected members of other
classes.
i.e. I want class A to have access to internal members of Class B
In C++ this was simple, as in the definition for class B, I would
declare calss A as a friend.

Seeing that C# had a friend keyword I thought this was going to be easy,
only to discover, that in typical Microsoft style, the friend keyword
has been changed to mean something completely different!

The only option I have come up with so far is to make public anything I
need to access from another class, but this doesn't really solve my
problem, as I want to make sure these functions can only be accessed by
the classes I specify.

Can anyone tell me how I can achieve the desired results please?
Thankyou in advance.

Paul Cheetham.
Nov 17 '05 #1
8 13700
Paul,

The closest thing you can do is use the internal keyword, and keep the
classes in the same assembly.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Paul Cheetham" <PA******@dsl.pipex.com> wrote in message
news:ue**************@TK2MSFTNGP12.phx.gbl...
Hi,

I am writing an application with a large number of various classes, and I
want some of them to have Friend access to protected members of other
classes.
i.e. I want class A to have access to internal members of Class B
In C++ this was simple, as in the definition for class B, I would declare
calss A as a friend.

Seeing that C# had a friend keyword I thought this was going to be easy,
only to discover, that in typical Microsoft style, the friend keyword has
been changed to mean something completely different!

The only option I have come up with so far is to make public anything I
need to access from another class, but this doesn't really solve my
problem, as I want to make sure these functions can only be accessed by
the classes I specify.

Can anyone tell me how I can achieve the desired results please?
Thankyou in advance.

Paul Cheetham.

Nov 17 '05 #2

"Paul Cheetham" <PA******@dsl.pipex.com> wrote in message
news:ue**************@TK2MSFTNGP12.phx.gbl...
Hi,

I am writing an application with a large number of various classes, and I want some of them to
have Friend access to protected members of other classes.
i.e. I want class A to have access to internal members of Class B
In C++ this was simple, as in the definition for class B, I would declare calss A as a friend.

Seeing that C# had a friend keyword I thought this was going to be easy, only to discover, that in
typical Microsoft style, the friend keyword has been changed to mean something completely
different!

The only option I have come up with so far is to make public anything I need to access from
another class, but this doesn't really solve my problem, as I want to make sure these functions
can only be accessed by the classes I specify.

Can anyone tell me how I can achieve the desired results please?


Check out the "internal" access modifier.
It's not exactly the same, but you can achieve similar results

Bill
Nov 17 '05 #3
Nicholas Paldino [.NET/C# MVP] wrote:
Paul,

The closest thing you can do is use the internal keyword, and keep the
classes in the same assembly.

Hope this helps.


Thankyou.

Unfortunately it doesn't help as all my classes need to be available
from outside the assembly.

I just can't believe that MS have destroyed such a useful type modifier!

Thanks.

Paul
Nov 17 '05 #4
I think it is a matter of opinion whether or not it is useful. If I had
to hazard a guess, the thinking at MS would be that types that are so
closely related should be packaged together.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Paul Cheetham" <PA******@dsl.pipex.com> wrote in message
news:ep**************@TK2MSFTNGP15.phx.gbl...
Nicholas Paldino [.NET/C# MVP] wrote:
Paul,

The closest thing you can do is use the internal keyword, and keep
the classes in the same assembly.

Hope this helps.


Thankyou.

Unfortunately it doesn't help as all my classes need to be available from
outside the assembly.

I just can't believe that MS have destroyed such a useful type modifier!

Thanks.

Paul

Nov 17 '05 #5

"Paul Cheetham" <PA******@dsl.pipex.com> wrote in message
news:ep**************@TK2MSFTNGP15.phx.gbl...
Nicholas Paldino [.NET/C# MVP] wrote:
Paul,

The closest thing you can do is use the internal keyword, and keep the classes in the same
assembly.

Hope this helps.
Thankyou.

Unfortunately it doesn't help as all my classes need to be available from outside the assembly.


You misunderstand.
The class can be public with SOME methods declared internal
Use these internal methods for 'friend' behavior
Outside of the assembly all of the public stuff will be visible

I just can't believe that MS have destroyed such a useful type modifier!


Wait till you know the facts before you bash them on this one.

Bill
Nov 17 '05 #6
See if the new Friend Assemblies concept of .NET Framework 2.0 meets your
needs:

Friend Assemblies (C# Programming Guide)
http://msdn2.microsoft.com/en-us/library/0tke9fxk.aspx

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

"Paul Cheetham" <PA******@dsl.pipex.com> escribió en el mensaje
news:ep**************@TK2MSFTNGP15.phx.gbl...
Nicholas Paldino [.NET/C# MVP] wrote:
Paul,

The closest thing you can do is use the internal keyword, and keep
the classes in the same assembly.

Hope this helps.


Thankyou.

Unfortunately it doesn't help as all my classes need to be available from
outside the assembly.

I just can't believe that MS have destroyed such a useful type modifier!

Thanks.

Paul

Nov 17 '05 #7
Bill Butler wrote:
You misunderstand.
The class can be public with SOME methods declared internal
Use these internal methods for 'friend' behavior
Outside of the assembly all of the public stuff will be visible


OK now I get it.
Certainly not perfect, as I was wanting to hide it more than that, but a
definite improvement on public.

Thankyou.

Paul
Nov 17 '05 #8
On Thu, 27 Oct 2005 15:14:17 +0100, Paul Cheetham
<PA******@dsl.pipex.com> wrote:
Seeing that C# had a friend keyword


Excuse me, but when was that? I've never seen a friend keyword in C#.
Last I checked only C++ and Visual Basic had that keyword (and the VB
variant means the same as "internal" in C#).
--
http://www.kynosarges.de
Nov 17 '05 #9

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

Similar topics

2
by: Christophe Barbe | last post by:
I am not clear about friend functions of a template class. GCC (3.3.2) wants me to add <> after the friend function names in the class declaration and VisualC++ doesn't like that. template...
1
by: Dmitry D | last post by:
Hi all, I'm having problems with declaring a template friend function. It seems like I've done everything as explained in C++ FAQ, but still, I'm getting the linker error (unresolved external...
5
by: Trevor Lango | last post by:
What is the appropriate syntax for placing a friend function that includes as one of it's parameters a pointer to the class object itself within the template class? I have the following: ...
15
by: Samee Zahur | last post by:
Question: How do friend functions and static member functions differ in terms of functionality? I mean, neither necessarily needs an object of the class to be created before they are called and...
9
by: Adam Badura | last post by:
I have code like this template<int size> big_int { /* ... */ template<int size2> friend class big_int<size2>; }; What I wanted to achive is to be able to easly convert different sized...
2
by: freegnu | last post by:
how to declare a friend function that can access two class it will look like the following class A { private: int i; public: A(){} ~A(){} friend void call(A &a, B &b);
6
by: ralphmerridew | last post by:
My current project involves reading a particular data format. It would be convenient to be able to do something like: class DataClass { friend bool FileRunner::read_data (const...
3
by: Filimon Roukoutakis | last post by:
Dear all, I have the following concept name { space1 { class Friend { };
5
by: Amit Gupta | last post by:
How do I do it (either by friend or by any other hack). I have three class, I am just writing derivation below: class A{} class B{} class C : public class B{} class D: public class B ()
6
by: WaterWalk | last post by:
I find friend declaration just very tricky. I tried the following examples on both MingW(gcc 3.4.2) and VC++ 2005. The results are surprising. Example1: namespace ns1 { class Test { friend...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.