通过另一类的成员函数调用一个类的成员功能
calling a member function of a class by member function of another class?
我有两个类A&B.我想通过B.的成员函数调用a的成员函数。
class A {
public:
void memberofa();
}
b类:
class B {
public:
void memberofb();
}
现在我需要从memberofb内部调用memberofa。任何建议和语法都将有助于
类似的东西?
class A {
public:
A() {};
void memberofa()
{
//you cant make object of B here because compiler doesn't see B yet
//if you do want to make Object of B here, define this function somewhere
//after definition of B class
printf("printing from member of An");
};
};
class B {
public:
B() {};
void memberofb()
{
printf("printing from member of Bn");
A objA;
objA.memberofa();
};
};
int main()
{
A a;
B b;
b.memberofb();
return 0;
}
- B继承自A
- B包含A对象
- A: :memberofa是静态函数
- A是singleton类
- A继承自B,B具有memberofa,它是虚函数
相关文章:
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 我们可以访问一个不存在的联盟的成员吗
- 为什么我不能在一个类的不同行中声明和定义成员变量?
- 我不小心调用了一个没有自己类对象的成员函数.但这是怎么回事呢
- 如何从另一个文件继承私有成员变量和公共函数
- C++-我可以创建另一个类的成员并在构造函数中使用它吗
- 是否可以同时声明一个类成员的常量/非常量?
- int数据类型的指针指向的是什么,如果是一个类的私有数据成员,我们创建了该类的两个对象?
- 在作为静态成员包含在另一个类中的类的构造函数中使用 cout
- 为什么将一个结构的引用设置为等于另一个结构只会更改一个数据成员?
- 我有一个对象,它将在整个程序的持续时间内实例化,但一个类成员不会,我应该动态分配它吗?
- C++ - 如何在结构向量中找到结构体一个成员的最大值?
- 如何定义一个没有重复代码的继承的 const 类成员函数?
- 没有公共构造函数作为另一个类模板成员的类模板
- 将另一个类的对象传递到当前类C++的构造函数中(不是成员初始化)
- 在 C++ 中声明 const 对象需要用户定义的默认构造函数.如果我有一个可变成员变量,为什么不呢?
- 将类成员函数作为线程调用到另一个类成员函数时发出警告消息
- 如何使用另一个类中的公共成员函数作为参数调用线程
- 访问超类类型成员对象的受保护成员 - 一个优雅的解决方案