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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:31:28+00:00 2026-06-01T18:31:28+00:00

i`m having this structure(array) which i want to fill with Class objects. What is

  • 0

i`m having this structure(array) which i want to fill with Class objects. What is the procedure to acomplish that. The tutorials i used/books weren’t that detailed and i don’t know how to do that.(since my tries failed)

ARRAY STRUCT
struct.h

struct Arr{

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

struct.cpp

void constr(Array &o){
    //Construct of 1*31 Matrix
    o=new Arr;
    o->days = days;
    o->M = new int[o->days];

CLASS

expe.h

class Expe {
private:
    int *obj;

public:
    Expe();
    ~Expe();

    void setObj(int ,int ,int ,int ,int ,int);
    void printObj();
    int getObj();
enter code here

expe.cpp

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

Expe::~Expe() {
    delete this->obj;
}

ps: I need to use my own struct vector.h is not allowed, and it has to be dyanmical

  • 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-01T18:31:29+00:00Added an answer on June 1, 2026 at 6:31 pm

    As the code is now, your Arr struct can hold an array of integers. If you want it to hold Expe objects you can define it as:

    struct Arr{
        int days;
        Expe* M;
    };
    

    or, better yet, make it a template class:

    template<typename T>
    struct Arr
    {
        int _size;
        T* M;
    };
    

    I also suggest moving the constructor inside the struct instead of the method constr:

    template<typename T>
    struct Arr
    {
        int _size;
        T* M;
        Arr(int size) : _size(size)
        {
            M = new T[size];
        }
        //manage the memory:
        ~Arr()
        {
            delete[] M;
        }
    };
    

    By using a template, you can specialize Arr however you want:

    Arr<int> x(10);  //creates an array of 10 int's
    Arr<Expe> y(10); //creates an array of 10 Expe's
    

    As a side-note, since this isn’t PHP, the this-> is not really necessary inside the class context, unless you have a local variable with the same name as a member, which you don’t.

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

Sidebar

Related Questions

Im having trouble working grabbing a dynamically created image from this service: http://opsin.ch.cam.ac.uk/opsin/USER-STRUCTURE-TO-GENERATE.png Im
I'm having a little trouble as I decide how to structure my projects. This
having this two classes I always have a doubt of which is the best
Im having a String array in my constructor which is supposed to read a
I'm having problem with my array basicly this is what i have: $test =
I'm having an asbolute nightmare dealing with an array of numbers which has the
TL;DR version: I want to avoid adding duplicate Javascript objects to an array of
I have an Array nested withing an Object that's inside an Object which is
Having this array: Array ( [_block1] => Array ( [list] => Array ( [sub-list]
Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here

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.