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

is there a way to do a C++ style friend class/function etc

Is there a way to allow C++ friend level access in a VB.NET object.

Simple C++ example.............

class Foo
{
friend class Bar;
private int a;
...
};

class Bar
{
private int b;
Bar(Foo f)
{
b = f.a; // accessing private data in Foo
}
...
};

Nov 20 '05 #1
4 1047
Well, you wont be able to access A because its declared private. A would
have to be declared Friend.
"Jeff Lindholm" <je*******@lindholm.org> wrote in message
news:M%********************@newssvr28.news.prodigy .com...
Is there a way to allow C++ friend level access in a VB.NET object.

Simple C++ example.............

class Foo
{
friend class Bar;
private int a;
...
};

class Bar
{
private int b;
Bar(Foo f)
{
b = f.a; // accessing private data in Foo
}
...
};

Nov 20 '05 #2
That would be fine, except that if A is declared Friend then anyone in the
current assembly would be able to access it. In the C++ example no class
other than Foo & Bar could access the private data.

class Foo
Friend a as integer
...
end class

class Bar
private f as new Foo
public sub New()
f.a = 10
end sub
end class

class OtherClass
private f as new Foo
public sub Subr()
f.a = 10
end sub
end class

Would still work, which is not what I am going for..............

(Also is this a top posting or bottom posting group - responding top since
that was how I was responded to)

"CJ Taylor" <no****@blowgoats.com> wrote in message
news:10*************@corp.supernews.com...
Well, you wont be able to access A because its declared private. A would
have to be declared Friend.
"Jeff Lindholm" <je*******@lindholm.org> wrote in message
news:M%********************@newssvr28.news.prodigy .com...
Is there a way to allow C++ friend level access in a VB.NET object.

Simple C++ example.............

class Foo
{
friend class Bar;
private int a;
...
};

class Bar
{
private int b;
Bar(Foo f)
{
b = f.a; // accessing private data in Foo
}
...
};


Nov 20 '05 #3
Jeff,
That would be fine, except that if A is declared Friend then anyone in the
current assembly would be able to access it. In the C++ example no class
other than Foo & Bar could access the private data.
There's no feature like C++ friend in VB.NET. The only way you can
make class Bar directly access private members of class Foo is to make
Bar a nested class inside Foo.

(Also is this a top posting or bottom posting group - responding top since
that was how I was responded to)


It's neither (or both). Do whatever you feel like. In a group as big
as this one people will never agree on one way.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 20 '05 #4

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:O3*************@TK2MSFTNGP11.phx.gbl...
Jeff,
That would be fine, except that if A is declared Friend then anyone in thecurrent assembly would be able to access it. In the C++ example no class
other than Foo & Bar could access the private data.
There's no feature like C++ friend in VB.NET. The only way you can
make class Bar directly access private members of class Foo is to make
Bar a nested class inside Foo.

(Also is this a top posting or bottom posting group - responding top sincethat was how I was responded to)


It's neither (or both). Do whatever you feel like. In a group as big
as this one people will never agree on one way.


Yes we do...


Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 20 '05 #5

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

Similar topics

35
by: wired | last post by:
Hi, I've just taught myself C++, so I haven't learnt much about style or the like from any single source, and I'm quite styleless as a result. But at the same time, I really want nice code and I...
2
by: Christophe Barbe | last post by:
I posted a few days ago about the same problem but was not very clear. So here is my second take at it. Basically with GCC 3.3.2, I can't compile the example from the C++ FAQ Lite available...
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: ...
12
by: Bryan Parkoff | last post by:
CMain Class is the base class that is initialized in main function. CA Class is the base class that is initialized in CMain::CMain(). CMain Class is always public while CA Class is always...
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...
6
by: Alice | last post by:
Hi -- I am trying to code a "mad libs" style program, in which the user puts in nouns, adjectives, etc., into text boxes. Then the user clicks on a button which opens a message box. Inside the...
4
by: Michael | last post by:
Dear all .. If I want to use develop a user control and declare a public property which the type is System.Windows.Forms.GridTableStylesCollection For example : Public Class LookAndView...
18
by: Joel Hedlund | last post by:
Hi! The question of type checking/enforcing has bothered me for a while, and since this newsgroup has a wealth of competence subscribed to it, I figured this would be a great way of learning...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.