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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:31:06+00:00 2026-05-28T23:31:06+00:00

How would I only return one dimension of an array, while ignoring the other?

  • 0

How would I only return one dimension of an array, while ignoring the other?

Such as:

int map[4][8];

int MapManager::getMapX(int x)
{
    return map[x];
}
  • 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-28T23:31:07+00:00Added an answer on May 28, 2026 at 11:31 pm

    Since none of the other answers here return an actual array (pointers are not arrays), I thought I might show how to really return an array. Or the closest thing possible, which is a reference to an array.

    typedef int row_type[8];
    
    row_type& MapManager::getMapX(int x) {
        return map[x];
    }
    

    What’s the point of this? The pointer works the same!

    No, it doesn’t. The pointer loses type information, namely, the size. You can make begin() and end() functions work with arrays, but you can’t with pointers:

    // pointer version
    int* MapManager::getMapX_ptr(int x) {
        return map[x];
    }
    
    row_type& row = getMapX(0);
    // row is of type int(&)[8]
    // notice the size is not lost in the type!
    std::sort(begin(row), end(row));
    // compiles fine! end() correctly finds the end of the row
    
    int* ptr = getMapX_ptr(0);
    // notice how ptr has no size information at all
    std::sort(begin(ptr), end(ptr));
    // can't possible be made to work!
    

    You can’t write end for int*.

    template <typename T, std::size_t N>
    T* end(T(&arr)[N]) {
        return &arr[0] + N;
    }
    
    template <typename T>
    T* end(T* ptr) {
        // what here?
        // guess?
        // pick a random number?
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anyone have any idea why shuffle() would only return 1 item? when using: $array2
I want to call a named_scope that will only return one record, but the
I'm wondering why my transaction log would only be 2 MB on my 40
I would like to be able to spawn a linux process that would only
I was thinking about how to create a program that would only be valid
I'd like to add a keyword to my language. This keyword would only have
I have trouble where, for some reason, SVN would only merge the newly generated
I want to make a registration page for clients, that would only contain a
How would I only allow users authenticated via Python code to access certain files
I have a special url which I would want only few people to have

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.