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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:43:56+00:00 2026-06-05T11:43:56+00:00

I’m sorry if I didn’t pick a descriptive or concise name. A lot of

  • 0

I’m sorry if I didn’t pick a descriptive or concise name. A lot of questions sound similar, but I haven’t been able to find what I’m looking for. What I want to do is store a 2D array of pointers somewhere and assign a variable in some object to that array to be able to access it.

Here’s some example code that has the same compile error I’m getting with a bigger project.

#include <iostream>
using namespace std;
struct X{
    float n, * b[8][8];
    X(){
        n = 1;
        b[1][5] = &n;
        cout << *(b[1][5]) << endl;
    }
    void Set(float * c[8][8]){
        b = c;
        cout << *(b[1][5]) << endl;
    }
};
main(){
    float m, * a[8][8];
    m = 2;
    a[1][5] = &m;
    X obj;
    obj.Set(a);
}

What I want to happen in this code is that an X object starts with its own 2D array, whose value pointed to by b[1][5] should be printed as “1”. Then the main method’s 2D array, a, is passed to the object’s Set() method and assigned to its array variable. The value pointed to by b[1][5] should then be printed as “2”.

However, I can’t figure out what type the Set() parameter, c, should be. I get

error: incompatible types in assignment of ‘float* (*)[8]’ to ‘float* [8][8]’

when I try to compile. As for why I want to do this, I’m trying to use an array of pointers to objects, not floats, but it’s the same error.

  • 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-05T11:43:59+00:00Added an answer on June 5, 2026 at 11:43 am

    Try this:

    #include <iostream>
    using namespace std;
    struct X{
        float n;
        float* (*b)[8];
        X(){
            n = 1;
            b = new float*[8][8];
            b[1][5] = &n;
            cout << *(b[1][5]) << endl;
        }
        void Set(float * c[8][8]){
            delete[] b;
            b = c;
            cout << *(b[1][5]) << endl;
        }
    };
    main(){
        float m, * a[8][8];
        m = 2;
        a[1][5] = &m;
        X obj;
        obj.Set(a);
    }
    

    Here, X stores a pointer to a 1D array, which we are treating as a pointer to the first element of a 2D array – i.e. as just a 2D array.

    In X‘s constructor, X allocates its own array with new and sets its pointer to point to that. When calling Set(), X deletes its own array, and sets its pointer to point to the array provided by the caller.

    The only thing to watch out for is, if you call Set() again, that array will in turn be deleted (which will blow up if that array is a stack array, like in this case). So, it might be advisable to separate the line that does delete[] b into its own member function, and call it only when necessary.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to construct a data frame in an Rcpp function, but when I
I used javascript for loading a picture on my website depending on which small

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.