【发布时间】:2014-07-17 14:16:37
【问题描述】:
所以我有一个名为 Weapon 的基类:
/*Weapon.h*/
#ifndef WEAPON_H
#define WEAPON_H
/*Weapon Class*/
class Weapon
{
int damage = 0,attackSpeed = 0;
public:
Weapon(int inDamage, int inAttackSpeed) : damage(inDamage), attackSpeed(inAttackSpeed) {};
还有一个继承Weapons属性的Sword类,我也想继承构造函数:
/*Sword.cpp*/
#include "Weapon.h"
#ifndef SWORD_H
#define SWORD_H
class Sword : public Weapon
{
public:
using Weapon::Weapon;//inherit weapons constructor
但是,当我在我的主函数中调用它时,它会收到一个错误,指出参数无效并且它不是构造函数:
/*Main.cpp*/
#include <iostream>
#include "Sword.h"
using namespace std;
int main()
{
Weapon weapon(5,5);
Sword sword(10,10); <-- Error here, invalid parameters
我想继承 Weapons 构造函数,但我一定是遗漏了一些东西。
【问题讨论】:
-
编译器是否完全支持C++11?
-
代码看起来没问题。看起来您的编译器不支持继承构造函数。这是更流行的编译器支持的一项或最新的 C++11 功能。
-
我正在使用 Visual Studio 2013 Professional,我认为它会......
-
看起来编译器不支持这个。
-
This table 暗示你的编译器还不支持继承构造函数。
标签: c++ inheritance constructor