简体   繁体   English

c ++:从另一个类调用一个类的变量

[英]c++ : calling a variables of a class from another class

I have a class lets say 我有一堂课可以说

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

another class 另一堂课

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 class is abstracted from the user(means he cant set the value of arguments of its member function here it is useVariableofABC ), user can only use ABC class .... Is it posible in c++... Do i need create a object of class ABC in xyz ...... xyz类是从用户抽象的(意味着他无法设置其成员函数的参数值在这里是useVariableofABC),用户只能使用ABC类...。在c ++中是可能的...我是否需要创建一个对象xyz中的ABC类的......

any suggestions plz ........ 任何建议请........

If the members of ABC aren't static , then yes, you do need an instance. 如果ABC的成员不是static ,那么是的,您确实需要一个实例。 And if you only want the arguments of xyz::UseVariablOfABC to be members of ABC , just pass that instance as parameter instead: 如果只希望xyz::UseVariablOfABC的参数成为ABC成员,则只需将该实例作为参数传递:

int xyz::UseVariablOfABC(const ABC&)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM