Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

class B;

class A

{

int Func1( B& b ) ;

int Func2( B& b ) ;

};

 

class B

{

private:

int _b;

friend int A::Func1( B& ); // Grant friend access to one

// function in class B.

};

int A::Func1( B& b ) { return b._b; } // OK: this is a friend.

int A::Func2( B& b ) { return b._b; } // Error: _b is a private member.

 

I want to declare in C# a function as friend, like up there ....

It is posible, and how?

  • Leaders
Posted
I want to acces a function or variable from a class without creating an object of that class.

 

It sounds to me like you are looking for the static modifier.

Snippet from MSDN

 

Members of a class are either static members or instance members. Generally speaking, it is useful to think of static members as belonging to classes and instance members as belonging to objects (instances of classes)...

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy
  • Leaders
Posted

[mshelp]ms-help://MS.VSCC/MS.MSDNVS/csref/html/vclrfstaticpg.htm[/mshelp]

 

Try that link and the example code in MSDN

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...