나는 튀김 기능을 아주 오랫동안 사용하고 있으며 아래와 같이 친구 기능을 사용하여 불완전한 코드를 완성하도록 지정되었습니다. C++에서 한 클래스의 멤버 변수를 다른 friend 함수를 사용하여 어떻게 액세스합니까?
//CODE GIVEN IN THE QUESTION NOT MEANT TO BE EDITED
#include<iostream>
using namespace std;
class store_keeper;
class item
{
char prod_name[30];
char prod_code[10];
float prod_price;
int stock_In_Hand;
public:
void get();
void print()const;
friend class store_keeper;
};
class store
{
int num_Of_Items;
item items[20];
public:
void get_details();
void print_details() const;
friend class store_keeper;
};
class store_keeper
{
char name[30];
char id[10];
public:
void get();
void print();
void stock_mgmt(store &);
};
//MY CODE
void item::get()
{
cin>>prod_name>>prod_code>>prod_price>>stock_In_Hand;
}
void item::print() const
{
cout<<prod_name<<prod_code<<prod_price<<stock_In_Hand;
}
void store::get_details()
{
cin>>num_Of_Items;
for(int i=0;i<num_Of_Items;i++)
{
items[i].get();
}
}
void store::print_details() const
{
for(int j=0;j<num_Of_Items;j++)
{
items[j].print();
}
}
void store_keeper::stock_mgmt(store &s)
{
for(int k=0;k<s.num_Of_Items;k++)
{
if(items[k].stock_In_Hand<10)
{
s.print_details();
}
}
}
//CODE GIVEN IN THE QUESTION NOT MEANT TO BE EDITED
main()
{
store s;
store_keeper sk;
s.get_details();
sk.stock_mgmt(s);
}
나는 손에 주식이 10.I 미만 num_Of_Items이 범위에서 선언하고 required.Thanks 경우 모든 수정 사항을 제안되지 않았 음 오류를 얻고되는 항목의 세부 사항을 표시했다.
개체 멤버 변수에 액세스하려면 * 인스턴스 *, * 개체 *가 필요합니다. 'stock_mgmt' 함수에는'store' 객체가 없습니다. –
그래서 올바른 store_keeper :: num_Of_Items를 저장해야합니다 :: num_Of _Items –
'stock_mgmt' 함수에서 이름이 지정된 인자가 필요합니다. 그런 다음 인수를 객체로 사용하십시오. –