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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:38:07+00:00 2026-06-02T01:38:07+00:00

I am working on a program and need to make an array of objects,

  • 0

I am working on a program and need to make an array of objects, specifically I have a 31×1 array where each position is an object, (each object is basically built out of 6 ints). Here is what I have but something is wrong and i could use some help thank you.

31×1 struct header”

const int days=31;

struct Arr{

    int days;
    int *M;
};
typedef Arr* Array;

31×1 matrix constructor:

void constr(){
    int *M;
    M = new Expe[31]; // Expe is the class 

class header:

class Expe {
private:
    //0-HouseKeeping, 1-Food, 2-Transport, 3-Clothing, 4-TelNet, 5-others
    int *obj;
}

Class object constructor:

Expe::Expe() {
    this->obj=new int[6];
}

help please… because i`m pretty lost.

  • 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-02T01:38:10+00:00Added an answer on June 2, 2026 at 1:38 am

    You should not use new unless you have to. You’re dynamically allocating memory which you have to manually delete afterwards.

    Instead, use statically allocated arrays:

    struct Arr{
        int days;
        Expe M[31];
    }
    

    This way you don’t need to construct M, it automatically is filled with 31 Expe objects.
    Same goes for the int array in Expe.

    (Hint: structs and classes are almost identical. They only difference is that default visibility for structs is public. Apart from that, structs can have member functions and constructors just like classes do.)

    If you have to use dynamic allocation you should follow this notation:

    X* variableName = new X[size];
    ...
    delete[] variableName; //Be sure to get rid of unused memory afterwards.
    

    Pointers should only be of type int* if you want to store an array of ints in it.

    You can also use const ints for array size declarations. So this is valid:

    const int size = 5;
    int X[size];
    

    You can use this to get rid of the “magic numbers” in your code.

    Typedefs like typedef Arr* Array; are typically used in C, not in C++ so much. There is hardly any situation where you would need to typedef something like this.

    If you post your entire code we might provide better help. It seems that you don’t only have one or two errors in your code, but also some fundamental understanding.

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

Sidebar

Related Questions

Im developing java program ,and I need to make it start working at each
I have a working C program where the length of an array of strings
I have been working on a program where I need to slowly and smoothly
I have a program in Perl I'm working on where I would need multiple
For my program I need to make a list of lists, with each sublist
I'm working on a program that will need to delete a folder (and then
I need to restart the program that im working on after an update has
I need to understand the working of this particular program, It seems to be
I have a working program in C++ that generates data for a Mandelbrot Set.
how can i make java program working with multiple languages (frensh, english , arabic

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.