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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:24:26+00:00 2026-05-26T20:24:26+00:00

Possible Duplicate: How do I use arrays in C++? I am not sure if

  • 0

Possible Duplicate:
How do I use arrays in C++?

I am not sure if how to do this in C++:

main()
{
   float array[5][4];   

   transpose(array); 
}

void transpose(float** array);

=> I got some some compilation error: vector<KeypointMatch, std::allocator<KeypointMatch> >

How can I pass the variable of two dimensional array to a method in C++?

Thanks in advance.

  • 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-26T20:24:27+00:00Added an answer on May 26, 2026 at 8:24 pm

    That would be okay if you were to read or modify the positions of the matrix, however you are going to modify the matrix itself. In your example, you’ll need to create another matrix.

    EDITED: I’ve modified this to use unique_ptr, because of the comments (though I don’t think the OP is really ready for/interested on this).

    EDITED I know you can transpose the matrix “in-place”. That was not the question from OP, however. Thanks to all commenters about this.

    std::unique_ptr<> is a class the lets you manage a pointer, assuring you that the pointer will be automatically deleted after using it. An option would be auto_ptr. Unfortunately, it it does not support vectors of arrays. unique_ptr does support them, though it is part of the new standard c++-0x.

    So, you need to modify the formal parameter of transpose to:

    void transpose(std::unique_ptr<float**> &array, int rows, int columns)
    {
        std::unique_ptr<float **> aux = array;
        array.reset( new float[columns][rows] );
    
        // now transpose aux into array
    }
    

    This also means that you cannot create the original array as you did:

    float array[5][4];
    

    This is a matrix on the stack, and you cannot expect to modify the pointer itself, it does not make sense. Better if you do:

    int main()
    {
        std::unique_ptr<float **>array( new float[5][4] );
        transpose( array, 5, 4 );
        // ... use array ...
    }
    

    That said, another solution is to slightly change the signature of the transpose procedure, and make it a function.

    std::unique_ptr<float **> transpose(float** array, int rows, int columns)
    {
        std::unique_ptr<float **> toret( new float[columns][rows] );
    
        // now transpose array into toret
    
        // end
        return toret;
    }
    

    .. and you would not need to change anything else in your program.

    int main()
    {
        float array[5][4];
        std::unique_ptr<float **> transposed( transpose( array, 5, 4 ) );
    
        // ... more things ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: Dynamic array in Stack? How do compilers treat variable length arrays Someone
Possible Duplicate: Why use iterators instead of array indices? string::iterator it; for (it =
Possible Duplicate: When should I use stdClass and when should I use an array
Possible Duplicate: PHP Sort a multidimensional array by element containing date I have some
Possible Duplicate: Why is Array.Length an int, and not an uint Is there is
Possible Duplicate: If you're not supposed to use Regular Expressions to parse HTML, then
Possible Duplicate: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result This is
Possible Duplicate: Use templates to get an array's size and end address Can someone
Possible Duplicate: When to use a List over an Array in Java? As the

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.