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 7891435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:37:05+00:00 2026-06-03T06:37:05+00:00

I have two c++ classes declared in headers. The base declares a virtual method

  • 0

I have two c++ classes declared in headers. The base declares a virtual method and the second class overrides it. The implementations are in .cpp files.

The code is fairly simple

void DefendProperty::apply(Queue<Defend*>* defendQueue, 
const Tool* toolSource, const Actor* actorSource, const Actor* defender) {
    cout << "BASE" << endl;
}

void DefendPropertyPhysical::apply(Queue<Defend*>* defendQueue, 
Tool* toolSource, const Actor* actorSource, const Actor* defender) {
    cout << "CORRECT" << endl;
    defendQueue->enqueue(new Defend(
        DefendTypePhysical::TYPE, 
        new DamageValuesPhysical(
        getRandomDouble(minDamageReduction, maxDamageReduction))
    ));
}

The point is that when I call the class instantiated as B, it outputs BASE, not CORRECT. I have no idea what’s going on at this point.

The classes are stored in a base ToolProperty type that doesn’t have the apply method. When they are called, they are typecasted into the DefendProperty type using dynamic_cast.

dynamic_cast<DamageProperty*>(node->value)->apply(damageQueue, toolSource, actorSource);

Any help would be appreciated

  • 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-03T06:37:07+00:00Added an answer on June 3, 2026 at 6:37 am

    The signature of the method in the derived class is different of the one in the base class. (One takes a const Tool*, the other a non-const Tool*)

    Because of the different signature the method of the derived class doesn’t override the method of the base class, but instead declares a new, unrelated method.

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

Sidebar

Related Questions

Say I have two different cpp files. Both declare classes with the same name,
I have a relationship between two base classes: public abstract class RecruiterBase<T> { //
I have two classes: Action and MyAction . The latter is declared as: class
I have two classes defined in different h files and each class has some
I have the following model classes declared by SQLAlchemy: class User(Base): id = Column(Integer,
I have two classes declared like this: class Object1 { protected ulong guid; protected
I have two classes declared as below: class User { public: MyMessageBox dataMsgBox; };
Suppose we have declared these two classes: public class Animal { //..... } public
I have two classes declared in C# code: public class A { public static
I have two classes in a PHP application, B extending A for example. Class

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.