Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-28-2003, 02:33 PM   #1
LQ Newbie
Registered: Jun 2003
Posts: 20

Rep: Reputation: 0
relation between classes


I have two classes. The first one contains a lot of variables that I would like to access directly from the second class without having to implement functions such as GetProperties()... and Set()...

How can I do that, what is the synthax? By friend functions or inheritance or ... ?

Thx a lot in advance.

Old 07-28-2003, 02:44 PM   #2
Senior Member
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
from what you say a friend class would be the best implementation. hopefully the following code should help.
class B;

class A
int p;
friend class B;
int whatIsP() { return p; }

class B
void setP(A& a, int b) { a.p=b; }

int main()
A a;
B b;

b.setP(a, 0);
cout << a.whatIsP();
b.setP(a, 1);
cout << a.whatIsP();

return 0;
have a look at for the syntax if ive done it wrong.

Last edited by kev82; 07-28-2003 at 02:47 PM.
Old 07-28-2003, 02:48 PM   #3
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
What language you are using would be nice...


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
the relation between udev,hal,kudzu? oriate Linux - General 3 10-27-2005 12:38 AM
OOP (PHP) classes and extended classes ldp Programming 3 03-05-2005 12:45 PM
What do you consider Apple to be in relation to Linux? apache363 General 49 05-12-2004 08:21 PM
IO problem in relation to PERL WeNdeL Linux - General 2 10-14-2003 04:51 PM
Solving a recursive relation .... SaTaN General 18 09-03-2003 10:39 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:14 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration