473,480 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

friend class

Dear all,
I would like to have an access from one class to the private variables of
other. But I also can't find a right sintax. The word "friend" seems to do
something else, VB compiler still complains.
-----C++--------

class A{
private:
int K;
}
class B{
friend class A;

void test(){
A oA;
A.K=10; //acccess private member
}
}
------VB----
Please help
Nov 21 '05 #1
4 1983
"Boni" <oilia@nospam> schrieb:
I would like to have an access from one class to the private variables of
other. But I also can't find a right sintax. The word "friend" seems to do
something else, VB compiler still complains.
-----C++--------

class A{
private:
int K;
}
class B{
friend class A;

void test(){
A oA;
A.K=10; //acccess private member
}
}


That's not supported.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
Is there a good solution?
I would like to have most class members private for all classes except for
one special, which has special handlers. What is a good design style to do
so?
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb im Newsbeitrag
news:OD**************@TK2MSFTNGP12.phx.gbl...
"Boni" <oilia@nospam> schrieb:
I would like to have an access from one class to the private variables of
other. But I also can't find a right sintax. The word "friend" seems to
do something else, VB compiler still complains.
-----C++--------

class A{
private:
int K;
}
class B{
friend class A;

void test(){
A oA;
A.K=10; //acccess private member
}
}


That's not supported.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

"Boni" <oilia@nospam> wrote in message
news:Oy**************@TK2MSFTNGP15.phx.gbl...
Is there a good solution?
I would like to have most class members private for all classes except for
one special, which has special handlers. What is a good design style to do
so?


A similar way?

Friend Class MyClass1
Friend Name As String
Friend Address As String
End Class

Public Class MyClass2
Private mMyClass As MyClass1

Public Sub New()
mMyClass = New MyClass1()
End Sub

Public Property Name() As String
Get
Return mMyClass.Name
End Get
Set
mMyClass.Name = Value
End Set
End Property

Public Sub SetAddress(ByVal Address As String)
mMyClass.Address = Address
End Sub
End Class
The difference is, any class in the assembly can access MyClass1 and it's
properties/methods. But, everything outside the assembly can't access
MyClass1 directly.

Mythran

Nov 21 '05 #4

"Boni" <oilia@nospam> wrote in message
news:er**************@TK2MSFTNGP15.phx.gbl...
I would like to have an access from one class to the private
variables of other.


You can't. If you need to be access a variable outside of a given
class, it has to be exposed, probably via a property.

Looking at your code, I would tend towards adding a Friend
method called something like "Prime", which class *in the same
assembly* can use to pass in a value, as in

Class A
Private K as Integer = Integer.MinValue

Friend Sub Prime( ByVal Value As Integer )
' Prevent Prime being called more than once
If K <> Integer.MinValue Then
Throw New ApplicationException()
End If

K = Value
End Sub

End Class

Class B
Private oA As New A

Sub New()
oA.Prime( 10 )
End Sub

End Class

HTH,
Phill W.
Nov 21 '05 #5

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

Similar topics

2
12501
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
4419
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
2680
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
6549
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
3718
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
2037
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
1719
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
3476
by: Filimon Roukoutakis | last post by:
Dear all, I have the following concept name { space1 { class Friend { };
5
2136
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
3143
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
6904
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
7080
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6735
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
6895
tracyyun
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...
1
4770
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
2992
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1296
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 ...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
176
bsmnconsultancy
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...

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.