الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

frindداله

مغلق
بدأه عبدالهادي الألمعي في 28 أبريل 2003 · 5 رد · 661 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

اعرف ان داله الفريند تصل الى الاعضاء الخاصه في الكلاس وتكون الداله خارج الكلاس ولكن كيف لا ادري كيف اتمنى يكون هناك مثال سهل يوضح هذا واتمنى يكون الكود كامل ولكم مني كامل شكري تحياتي

لكم مني خالص التقدير

*********************

دروس الاكسس

قاعدة بيانات بالسي++

قاعدة بيانات اخرى بالسي++

الفريق العربي للبرمجه

*********************

كان الله في عون العبد مادام العبد في عون اخيه

#2

try with this Code, Sorry if I have many Errors Ihaven't C++ Compiler

public class A
{
frind: class B;   
private: 
   int x;
   public: 
    A(int z);
    void setX(int z);
    int getX();

 };

public class B
{
private: int  y;   
public: 
    void setY(A a);

};
public class C
{
private:
int z;
public:
void setZ(A a);

};
A::A(int z)
{
   x=z;
}

int A::getX()
{
return x; 
}

void A::setX(int z)
{
    x=z;
}

void B::setY(A *a)
{
  y=a->x; /*its Correct */
}

void C::setZ(A *a)
{
  z:=a->x;/* error becuse x is Private in A*/
z:=a->getX();/* OK*/
}

void main()
{
A *a;
B *b;
C *c;
a=new A(5);
b=new B();
c->new C();
b->setY(a);

c->setZ(a);
}
اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء
#3

the Code is corrected

#include 
class A;
class B;
class C;

class A
{
	friend class B;   
	private: 
	int x;
	 public: 
		A(int z);
		void setX(int z);
		int getX();
		void describeMe();

 };

class B
{
		private: int  y;   
		public: 
		void setY(A*  a);
		void describeMe();

};


class C
{
	private:
			int z;
	public:
		void setZ(A *a);
		void describeMe();

};


A::A(int z)
{
   x=z;
}

void A::describeMe()
{
	cout<<"nIm a Instance for class A and my value is:"<}

int A::getX()
{
	return x; 
}

void A::setX(int z)
{
    x=z;
}

void B::setY(A *a)
{
  y=a->x; /*its Correct */
}

void B::describeMe()
{
	cout<<"nIm a Instance for class B and my value is:"<}

void C::setZ(A *a)
{
	//z:=a->x;/* error becuse x is Private in A*/
	  z=a->getX();/* OK*/
}

void C::describeMe()
{
	cout<<"nIm a Instance for class C and my value is:"<}

void main()
{
A *a;
B *b;
C *c;
a=new A(5);
b=new B();
c=new C();
b->setY(a);

c->setZ(a);

a->describeMe();
b->describeMe();
c->describeMe();
};
اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء
#4

كثر خيرك الله عليك بس ودي تشرح لي اليه العمل للفرند في هالبرنامج ولا عليك امر

لكم مني خالص التقدير

*********************

دروس الاكسس

قاعدة بيانات بالسي++

قاعدة بيانات اخرى بالسي++

الفريق العربي للبرمجه

*********************

كان الله في عون العبد مادام العبد في عون اخيه

#5

I make it in the next days

اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء
#6

1 we have 3 classes A,B and C

2 in the Class A we have defined some variable as Private

3 The Class B is friend from class A, but Class C is not friend from A

4 in the Class B we can used the Private variable of Class A

for Examble

void B::setY(A *a)
{
  y=a->x; /*its Correct  becuse B is friend of A*/
}

5 in the Class C we can't use the private variable of class A but we can uese the public members or methods

For Examble

void C::setZ(A *a)
{
    z:=a->x;/* error becuse x is Private in A*/
z=a->getX();/*Ok becuse getx() is public*/


}

if u don't understand me please send me email in Arabic and I'll help u

اللهم انا نسألك علما نافعا ونعوذ بك من حماقة الجهلاء

هذا الموضوع مغلق.