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

J

Jeff Lindholm

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
}
...
};
 
C

CJ Taylor

Well, you wont be able to access A because its declared private. A would
have to be declared Friend.
 
J

Jeff Lindholm

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)
 
M

Mattias Sjögren

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
 
C

CJ Taylor

Mattias Sjögren said:
Jeff,


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.



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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top