Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如果我只知道C+中的基类,如何包含派生类+;_Java_C++_Inheritance - Fatal编程技术网

Java 如果我只知道C+中的基类,如何包含派生类+;

Java 如果我只知道C+中的基类,如何包含派生类+;,java,c++,inheritance,Java,C++,Inheritance,如果我有一张基类卡。现在我有了一个名为DeckOfCard的类,它包含几个卡片: class DeckOfCard { private: vector<Card> deck; //.... } 如何在C++中实现这一点?感谢您的建议。:-) 使用指向父类的指针,即卡* class-DeckOfCard { 私人: 向量甲板; //.... } 假设您有一个从卡公开继承的类扑克卡,下面的语句是有效的 PokerCard *pcard =

如果我有一张基类
。现在我有了一个名为
DeckOfCard
的类,它包含几个卡片:

class DeckOfCard
{
    private:
         vector<Card> deck;
         //....
}

如何在C++中实现这一点?感谢您的建议。:-)

使用指向父类的指针,即
卡*

class-DeckOfCard
{
私人:
向量甲板;
//....
}
假设您有一个从
公开继承的类
扑克卡
,下面的语句是有效的

PokerCard *pcard = new PokerCard();
deck.push_back(pcard);
PokerCard *pcard = new PokerCard();
deck.push_back(pcard);