C :从另一类调用类的变量
c++ : calling a variables of a class from another class
我有一个类,请说
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&)
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 将数组的地址分配给变量并删除
- 为"adjacent"变量赋值时出现问题
- 如何为同一类对象的成员函数保留单独的变量副本?
- 无法从类中的其他功能访问同一类的变量
- C 将在类中创建的线程共享同一类变量
- 希望静态成员函数调用同一类的成员变量
- 如何在另一类设置静态变量
- C :从另一类调用类的变量
- 方法无法访问同一类的成员变量 (C++)
- 访问同一类的其他对象的变量
- C++继承:作为成员变量的同一类的两个子类
- 不允许直接在同一类中访问成员变量
- 通过同一类的私有成员访问私有成员变量
- 我无法使用类变量作为同一类函数的默认参数
- 在同一类的方法中使用类的静态成员变量
- 一个类的方法可以't访问同一类的int变量
- 如何在具有 2 个实现的同一类中保留静态变量的值
- 尝试返回同一类中的私有变量时C++ "Getter"方法抛出访问冲突