Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8260857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:11:56+00:00 2026-06-08T03:11:56+00:00

I am attempting to implement an interface in C++ for a game that I

  • 0

I am attempting to implement an interface in C++ for a game that I am writing and I am running in an error.

Here is the interface and its subclass that I created:

//Attack.h
//defines a set of values associated with all attacks
//and an interface for all attacks
typedef unsigned const int attack_type;
typedef unsigned const int p_attack_type;
//defines the attack types
static const attack_type NORMAL = 0;
static const attack_type ADDER = 1;
static const attack_type MULTIPLIER = 2;
static const attack_type AREA_OF_EFFECT = 3;
static const attack_type DAMAGE_OVER_TIME = 4;
static const attack_type STATUS = 5;

//String representation of the names of attack types
static std::string attack_types [] = {"Normal","Adder","Multiplier","Area-Of-Effect","Damage-Over-Time","Status"};

class Attack
{
    protected:
        std::string attack_name;//the name of this attack
        attack_type type;//the type of attack this represents
        int cool_down_turns;//represents the number of turns this ability cannot be used after being used
        bool causesGlobalCooldown;//does this attack cause ALL abilities to cooldown -- during combat should force cooldown on everything
        bool on_cool_down;

    public:
        Attack(std::string name, attack_type, int cooldown_t, bool causesGlobalCooldown = false)
        {
            this->attack_name = name;
            this->type = attack_type;
            this->causesGlobalCooldown = causesGlobalCooldown;//whether or not ALL abilities need to cooldown
            this->cool_down_turns = cooldown_t;//amount of turns that cooldown occurs
            this->on_cool_down = false;//whether or not this attack is on cooldown
        }

        //the main method called to perform this attack
        //calculate damage, calculate cooldown -- for spells calculate cost
        //return the amount of damage this attack does
        virtual int do_attack(int modifier, int roll)
        {
            //calculate damage
            int damage = calculate_damage(modifier,roll);
            //check cooldown
            if(this->cool_down_turns>0)
            {
                this->cooldown(true);
            }
            return damage;
        }

        //defined by sub classes -- useful to tell you how much damage the attack is going to do
        virtual int calculate_damage(int modifier, int roll) = 0;

        //**standard method definitions**//

        //get the attack name
        std::string get_attack_name() const
        {
            return this->attack_name;
        }

        //get the attack type
        attack_type get_attack_type() const
        {
            return this->type;
        }

        //get the attack type name of this attack
        std::string get_attack_type_name() const
        {
            return attack_types[this->type];
        }

        //check the cooldown status of this attack
        bool cooldown() const
        {
            return on_cool_down;
        }

        //set the cooldown status of this attack
        void cooldown(bool set)
        {
            this->on_cool_down = set;
        }


};

Here is the subclass :

/*
 * Normal.cpp
 *
 *  Created on: Jul 15, 2012
 *      Author: christian
 *      Standard Definition of a Normal attack
 */
#include "Attack.h"

class Normal : public Attack
{
    public:

        Normal(std::string name)
        {
            Attack(name,NORMAL);
        }

        int calculate_damage(int modifier, int roll) const
        {
            return roll + modifier;
        }
};

The error being returned from the compiler is :
The type ‘Attack’ must implement the inherited pure virtual method ‘Attack::calculate_damage’

Does anyone know the correct syntax for this? Do I have the inheritance setup correctly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:11:58+00:00Added an answer on June 8, 2026 at 3:11 am

    The const in your derrived class makes your derrived class’s method’s signature different from the virtual method in the base class. As far as the compiler is concerned you’ve overloaded calculate_damage in the Normal class, giving it a const and non-const version.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently attempting to implement a custom gridview interface to display data from
Attempting to implement a poor man's test of whether a process is still running
I am attempting to implement a form on APEX that allows the user (in
I am attempting to implement thread-safe usage of ConcurentHashMap within singleton spring service that
I'm attempting to implement OpenID with ASP.NET MVC (Yeah, we haven't heard that one
I'm attempting to implement the IObservable interface in C# using Mono 2.10.6, and Monodevelop
I am attempting to load a set of JAR files that go together to
I'm attempting to return all Animal objects that implement IHerd. Could someone point me
I am attempting to override a method declaration within an interface that extends another
I'm attempting to implement a decorator on certain methods in a class so that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.