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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:45:17+00:00 2026-05-20T20:45:17+00:00

In C++, I want my class to have a char** field that will be

  • 0

In C++, I want my class to have a char** field that will be sized with user input. Basically, I want to do something like this –

char** map;
map = new char[10][10];

with the 10’s being any integer number. I get an error saying cannot convert char*[10] to char**. Why can it not do this when I could do –

char* astring;
astring = new char[10];

?

  • 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-20T20:45:18+00:00Added an answer on May 20, 2026 at 8:45 pm

    Because an array is not a pointer. Arrays decay into pointers to their first elements, but that happens only at the first level: a 2D array decays into a pointer to a 1D array, but that’s it—it does not decay into a pointer to a pointer.

    operator new[] allows to allocate a dynamic array of a size only known at runtime, but it only lets you allocate 1D arrays. If you want to allocate a dynamic 2D array, you need to do it in two steps: first allocate an array of pointers, then for each pointer, allocate another 1D array. For example:

    char **map = new char*[10];  // allocate dynamic array of 10 char*'s
    for(int i = 0; i < 10; i++)
        map[i] = new char[10];  // allocate dynamic array of 10 char's
    

    Then to free the array, you have to deallocate everything in reverse:

    for(int i = 0; i < 10; i++)
        delete [] map[i];
    delete [] map;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that I want to contain multiple objects of something I
In a Django project as models I have something like that: class Company(models.Model): name
I have a function ClassA::FuncA(const char *filePath) and want to copy this const char
I have class and I want to initalize column that stores pictuer with type
I have a class PlaylistTrack that I want to extend class Song. When I
I want to have a class property that allow for an expression to take
A noob here. I have a model class where I want to save something
General I have two kind of users, and one field (cluster) that I want
I am working with some tables where I want the C# class to have
I have class A: public B { ...} vector<A*> v; I want to do

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.