简体   繁体   中英

Use member function of another class without object and avoid static

This question is different from those duplicated ones.

I have 2 classes A and B. B has a member function B::boy that uses its variable b .

A has a member function A::evaluate and in this member function, I need to use B::boy .

The problem now is that :

1) B::boy cannot be static because it needs to use a non-static variable b .

2) I cannot instantiate a object of B in A. Because I have one object of B elsewhere and that stores the variable b that is also useful in A.

Is it not possible to be done in C++?

b作为A::evaluate的参数传递,或者在 A 中有 B 的指针或引用成员(取决于b值在A类中的“有用”程度)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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