所以我有一个名为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) {};
一个名为Sword的类继承了Weapons属性,我也希望继承构造函数:
/*Sword.cpp*/
#include "Weapon.h"
#ifndef SWORD_H
#define SWORD_H
class Sword : public Weapon
{
public:
using Weapon::Weapon;//inherit weapons constructor
然而,当我在我的main函数中调用它时,它会收到错误,说参数无效且不是构造函数:
/*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构造函数,但我必须遗漏一些东西。
答案 0 :(得分:2)
@Mike Seymour似乎是对的, Microsoft Visual Studio 2013 does not support inheriting constructors。