C :从另一类调用类的变量

c++ : calling a variables of a class from another class

本文关键字:一类 变量 调用      更新时间:2023-10-16

我有一个类,请说

class ABC
{
   int x;
   char y;
  ....
}

另一个类

class xyz{
   int UseVariablOfABC(int a,char b)
   // a and b are the variables/members declared in class ABC above
}
int xyz::UseVariablOfABC(int a,char b){
//Do some thing with a and b
}

xyz类是从用户中抽象的(意味着他无法在此处设置其成员函数的参数值,这是Usevariable ofabc),用户只能使用ABC类。...它在C 中是否适合...我需要...在xyz中创建ABC类的对象......

任何建议plz ........

如果ABC的成员不是static,那么是的,您确实需要一个实例。而且,如果您只希望xyz::UseVariablOfABC的参数是ABC的成员,则只需将该实例作为参数传递:

int xyz::UseVariablOfABC(const ABC&)