user3044002
user3044002

Reputation: 59

Inheriting Constructors in C++

So I have a base class called 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) {};

And a class called Sword that inherits Weapons attributes, I want to inherit the constructor too:

/*Sword.cpp*/
#include "Weapon.h"
#ifndef SWORD_H
#define SWORD_H
class Sword : public Weapon
{
public:
    using Weapon::Weapon;//inherit weapons constructor

However when I called it in my main function it gets an error saying the arguments invalid and its not a 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

I want to inherit Weapons constructor, but I must be missing something.

Upvotes: 2

Views: 165

Answers (1)

user3044002
user3044002

Reputation: 59

@Mike Seymour seems to be right, Microsoft Visual Studio 2013 does not support inheriting constructors.

Upvotes: 2

Related Questions