我有一些看起来像这样的代码
class Split
{
public:
Split(Hand *pcHand = NULL)
: phand(pcHand), phandsplit(pcHand)
{
}
int CardOne;
int CardTwo;
int CardThree;
void getCardOne(Hand & phand)
{
CardOne = phand.SendCOneToSplit();
std::cout << "Card One: " << CardOne << std::endl;
}
void getCardTwo(Hand & phandsplit)
{
CardTwo = phandsplit.SendCOneToSplit();
std::cout << "Card Two: " << CardTwo << std::endl;
}
void getCardThree(Hand & phandsplitTwo)
{
CardThree = phandsplitTwo.SendCOneToSplit();
std::cout << "Card Two: " << CardTwo << std::endl;
}
private:
Hand * phand;
Hand * phandsplit;
};
我想让它成为一个函数,而不是需要添加另一个函数,它只对同一类的不同对象执行完全相同的操作。有没有办法做到这一点?如果是这样,谁能指出我正确的方向?