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

  • Home
  • SEARCH
  • 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 1113271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:49:56+00:00 2026-05-17T02:49:56+00:00

In C++ I have an array of pointers to Player objects and want to

  • 0

In C++ I have an array of pointers to Player objects and want to fill it with Fickle objects where Fickle is a class that is derived from Player. This is because I want a general Player array that I can fill with different objects from different classes that all are derived from the Player class.

How can I do this?

I create an array of pointers to Player objects

Player ** playerArray;

Then initialize the array to a certain size

playerArray = new Player *[numPlayersIn];

But then the following does not work for some reason:

playerArray[i] = new Fickle(0);

How can I fill the playerArray with Fickle objects (Fickel is a class derived from Player) ?

Thanks.

UPDATE:

I get the error message (in Eclipse IDE):

expected ';' before 'Fickle'

I think it might be something to do with the definition of Fickle.

The Fickle.hpp file contains:

#pragma once
#include "player.hpp";

class Fickle: public Player {
public:
    // constructor
    Fickle(int initChoice){
        choice = initChoice;
    }
}

Is this OK or is there a problem with this?

The Player class header file has:

class Player {
private:

public:
    int getChoice();
int choice; // whether 0 or 1
virtual void receive(int otherChoice); // virtual means it can be overridden in subclases
};

The receive method will be overridden in Fickle and other classes derived from the Player class

UPDATE 2:

OK I think the error is actually due to a different part of the code.

Player defines a method receive:

virtual void receive(int otherChoice);

That should be overridden by the subclass Fickle but the definition in Fickle:

void Fickle::receive(int otherChoice) {}

gives the error:

no 'void Fickle::receive(int)' member function declared in class 'Fickle'

But I don’t know why this is because receive is defined in the Player class?

  • 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-05-17T02:49:57+00:00Added an answer on May 17, 2026 at 2:49 am

    While you probably should be using a vector instead, there’s no real reason a dynamically allocated array can’t work. Here’s a bit of working demo code:

    #include <iostream>
    
    class Player {
    public:
        virtual void show() { std::cout << "Player\n"; }
    };
    
    class Fickle : public Player {
    public:
        virtual void show() { std::cout << "Fickle\n"; }
    };
    
    int main() {
        Player **p = new Player *[2];
        p[0] = new Player;
        p[1] = new Fickle;
    
        for (int i=0; i<2; i++)
            p[i]->show();
    
        for (int i=0; i<2; i++)
            delete p[i];
        delete [] p;
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.