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. 8 13726
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.co m
"Paul Cheetham" <PA******@dsl.p ipex.com> wrote in message
news:ue******** ******@TK2MSFTN GP12.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.
"Paul Cheetham" <PA******@dsl.p ipex.com> wrote in message
news:ue******** ******@TK2MSFTN GP12.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
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
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.co m
"Paul Cheetham" <PA******@dsl.p ipex.com> wrote in message
news:ep******** ******@TK2MSFTN GP15.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
"Paul Cheetham" <PA******@dsl.p ipex.com> wrote in message
news:ep******** ******@TK2MSFTN GP15.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
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.p ipex.com> escribió en el mensaje
news:ep******** ******@TK2MSFTN GP15.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
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
On Thu, 27 Oct 2005 15:14:17 +0100, Paul Cheetham
<PA******@dsl.p ipex.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 <class T>
class test{
test(void);
~test(void);
friend bool operator== <> (const test<T> &p1, const test<T> &p2);
}
|
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
'aFunc(A<char> const&)' ) in
the following sample program. Tried it on GCC and Borland's compiler.
Can somebody please show me the correct way to fix this?
Thanks,
Dmitry
|
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:
//****************************************************
// testClass.h
//****************************************************
#ifndef TESTCLASS_H
|
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 either has access
only to static members of the class (ie. assuming no object of the
class is in scope - neither by arguments recieved nor by local
declarations). Any static member function like this:
//accessing static member i
static void...
|
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
big_int's and to operate on them. But for this I need to be able to access
private data of big_int. The problem is that for differenc sizes this are of
| |
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);
|
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 vector<string>&);
...
};
class OtherDataClass {
|
by: Filimon Roukoutakis |
last post by:
Dear all,
I have the following concept
name {
space1 {
class Friend {
};
|
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 ()
|
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 void func()
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |