[英]Lets say dad class have two child object class. How can call functions these childs from each others ? C++
我想在標題上說:
游戲
#include "player.h"
#include "network.h"
class game
{
public:
player p1;
network net;
}
網絡
class network
{
public:
void networkFunction1();
}
當我在player.cpp中時,我想到達networkFunction1();
有幾種方法。 其中之一是將network
地址傳遞給player
, player
以后可以使用它:
class player {
network *net;
public:
void setNetwork(network *netPtr) {
net = netPtr;
}
}
class game {
public:
player p1;
network net;
game() {
p1.setNetwork(&net);
}
}
然后,在player
類的方法中,您可以像這樣使用network
:
net->networkFunction1();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.