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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:34:25+00:00 2026-06-17T08:34:25+00:00

So here’s what I got in a nutshell. I have a base item class

  • 0

So here’s what I got in a nutshell.

  1. I have a base item class from which, potions, equipment, spells, etc.. are derived and several classes are derived from those and so on. Note: some derived classes have non-virtual class-specific member functions / data types.

  2. I have also created a “random” armor/weapon generator.

What I want to have is an inventory kind of like this:

struct Hero_Inventory
{
   std::vector<Spell*> Spell_Inventory;
   std::vector<Potion*> Potion_Inventory;
   std::vector<Equipment*> Equipment_Inventory; 

   Hero_Inventory() {}
};

Creating a container (inventory) for my spells and potions has been pretty straight forward. As they will be predefined. Using polymorphism and pointers wont be a problem

My main problem is figuring out to store and use (ex. access the weapon-class’s specific member functions) my randomly generated weapons / armor (which are both derived from Equipment).

I would like for all of my “Equipment” to be in one container.

I’m generating all of my Equipment in a few functions so when I finish the generation process and end up with something like this:

Equipment * TestArmor = new Armor(/* Bunch of parameters go here */);

I don’t know what to do with it, because as soon as that function goes out of scope I loose that pointer. And without pointers / referencing I can’t use polymorphism, which is allowing me to keep my Equipment all in one container.

I’m really lost at this point and I’m looking for any suggestions or alternatives people can suggest. If you need more code I’ll post it, just tell me what part(s) your interested in.

Sorry if I’ve been vague, this is my fist post. I’m usually pretty good at figuring things out on my own but this thing has me beat. If anyone needs more information ask and I’ll try to provide it.

Thanks in advance,
-Ryan

  • 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-17T08:34:27+00:00Added an answer on June 17, 2026 at 8:34 am

    Create a uniform interface for manipulating the Equipment objects:

    class Equipment {
    public:
        virtual void render(Renderer& renderer) = 0;
        virtual void createController(ControllerManager& controllerManager) = 0;
        virtual void load(std::istream& input) = 0;
        virtual void save(std::ostream& output) = 0;
    };
    

    The function createController is interesting as the equipment will be able to tell the ControllerManager how to create something that will manipulate its exact values.

    If you want a function which allows interaction with other Equipment objects, you probably need the Visitor Pattern. This is a way of introducing polymorphism based on multiple types rather than a single type.

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

Sidebar

Related Questions

Here are the tables I have: Table A which has entries with item and
Here is the code I have. This is my PrintToFile class import java.util.*; import
Here is the scenario: I have several CIFS partitions which AD-based users can mount
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Here's some sample HTML <style> .icon {display:none;} </style> <ul> <li>ABC <i id=abc class=icon>x</i></li> <li>DEF
Here is the two scripts I have Script 1: <? include('config.php'); $json = $_POST['payload'];
Here is my AsyncTask. Getting exception in the AsyncTask.. private class GetCategories extends AsyncTask<String,
here Html given below <div class=navBulletsWrapper> <div rel=0 class=></div> <div rel=1 class=></div> <div rel=2

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.