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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:10:19+00:00 2026-05-20T14:10:19+00:00

Need for two dimensional array of objects that could be something like: myContainer<myObject*> *a

  • 0

Need for two dimensional array of objects that could be something like:

myContainer<myObject*> *a = new myArray<myObject*>( 20, 20 ); // passing int's as width & height 

later accessing values would be done with methods such as:

mylist<myObject*> getRow( int );
mylist<myObject*> getColumn( int );
mylist<myObject*> getDiagonalRow( int );

implementations of those could be something like:

myList<myObject*> myContainer::getRow( int a ){
    if( a < 0 && a>=this->height ) 
        return; 
    myList<myObject*> hlp;
    for( int i=0; i<this->width; i++)
        hlp.append( this->arr[a][i] );
    return hlp; // returns a copy. Could also be a pointer if created with new.
}

Other methods could follow similar lines, ie. creating a list object and filling it with what was requested.

My questions: Can anyone think of elegant way to create a container class I’m describing here. Which could for example avoid creating and filling of list-objects but still maintaining the abstraction and/or usability. Or please advice if I have missed something in STL etc. that has something like this.

  • 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-20T14:10:19+00:00Added an answer on May 20, 2026 at 2:10 pm

    STL has the valarray container which can be viewed as row and columns using slices, but you have to do it manually or wrap it into a wrapper class. Also the slices represents the values of the valarray (they are not a copy), but it is designed to be used with numbers and to be a bit optimized, it doesn’t have any iterator and cannot be grown. it’s doesn’t follow the usual STL container concept. but it can still be used as a quick and dirty workaround if you can’t use boost.

    std::valarray<float> array(16);
    // we can view it as a 4x4 matrix.
    // this represents the first line
    array[std::slice(0,4,1)];
    // and the second column
    array[std::slice(1,4,4)];
    // you cannot use the sliced array directly. they don't
    // have operator[], but they have operator=(valarray), and
    // valarray has a constructor that takes sliced arrays as input.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a two dimensional array that I need to load data into. I
I need to create a mutable two-dimensional array in Objective-C. For example I have:
I have an single-dimensional array of PHP objects. Each object has two attributes, one
How do I add objects to a two-dimensional array? The array is initiated with
I need two divs to look a bit like this: | | ---| LOGO
In Java how do you convert a ArrayList into a two dimensional array Object[][]?
guys. Here's a simple sample two-dimensional array in PL/SQL, which is working perfectly. declare
I have a need to store multiple datatypes(like int or string mostly) inside a
I've got a two dimensional array and I want to apply a function to
I have a two dimensional array, i.e. an array of sequences which are also

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.