【问题标题】:How to inherit from my custom class如何从我的自定义类继承
【发布时间】:2014-11-22 09:45:16
【问题描述】:

我在 Qt 中创建了一个具有许多公共属性的类

class items
{
public:
    QString name;
    QString description;

如何创建一个新类来继承该类的所有变量和方法?

【问题讨论】:

  • 类派生:公共项目不是吗?
  • 别问我:P,我所做的是 class newItem: public items 但我不确定我是否理解正确。 'items' 类有自己的构造函数,它在哪里被调用?

标签: c++ qt inheritance


【解决方案1】:

您的问题是关于 c++ 而不是 Qt。可以搜索c++文档了解c++ inheritance

你可以这样继承另一个类:

class myClass : public items
{
    myClass() : Item()
    {
       //
    }
}

【讨论】:

  • 我确实懂一些 c++,我正试图重做本教程 (penguinprogrammer.co.uk/rpg-tutorial-2/items),但对 10|Weapon(std::string name, std:: string description, int damage, double hitRate) : Item(name, description)
  • 在myClass的构造函数中调用item的构造函数。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多