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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:26:36+00:00 2026-05-26T19:26:36+00:00

I read that you can declare an aray of objects by this line Enemy

  • 0

I read that you can declare an aray of objects by this line

Enemy * d = new Enemy[2];

but when i tried to make a 2 dimensional array, there was an error where this cant be initialized. I also tried this

Enemy *enemies[6][2];

but i am not sure how to reference to each object in that array and and how to pass that reference to a function.

  • 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-26T19:26:36+00:00Added an answer on May 26, 2026 at 7:26 pm

    You need to use a pointer to a pointer in order to make a jagged array.

    Enemy** d = new Enemy*[6];
    for (size_t i = 0; i < 6; ++i)
        d[i] = new Enemy[2];
    

    If you plan on making a fixed size array, you can just create it the same as you would a normal array.

    Enemy enemies[6][2];
    

    You then just reference them using two indices.

    enemies[2][1].roar();
    

    Note: You will find that multi-dimensional arrays tend to lead to more headaches than they are worth. It is much cleaner to maintain a single dimension array and simply index it based on the number of rows and columns.

    Enemy* enemies = new Enemy[rows * cols];
    
    Enemy* getEnemy(size_t row, size_t col)
    {
        return enemies + (row * cols + col);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read that you can do it, but would this really improve performance
I like the new Dynamic keyword and read that it can be used as
I have read that if you declare two structs like this: struct Node {
I've read that there is no way that JQuery can download a file directly,
I'm building a plugin system for my application. I've read that anyone can decomple
Is there any tool that can read a WSDL file and based on the
Is there any class in the .NET framework that can read/write standard .ini files:
Is there a stand-alone GUI designer that can read and write the .form files
I'm trying to find a library that can read a given RSS/Atom feed, and
To my surprise and delight I read that an adminsitrator can import (nearly directly)

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.