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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:54:30+00:00 2026-05-20T07:54:30+00:00

UPDATE : Answer at the bottom. Hi Guys, How to initialize an ‘array of

  • 0

UPDATE :
Answer at the bottom.

Hi Guys,

How to initialize an ‘array of pointers to a struct’ ? The catch is, the array is a member variable and the size passed to the declaration of the array in the constructor is variable entity.


    typedef struct Node {
        string key;
        int value;
        struct Node * left;
        struct Node * right;
    }doubly;

    class myHashStrKey{

    private:
        size_t hashsize;
        doubly * table[];

    public:
        myHashStrKey(){
            hashsize = ((size_t)-1);
            doubly * table[hashsize];
            memset(table,NULL,hashsize);// This is giving segmentation fault
        }

    };

//Called constructor;    myHashStrKey sss = myHashStrKey();

Here I want the table to be a array of pointers to the Doubly nodes and I want all the pointers to be initialized to NULL . Whats wrong with this code here ? What other better way are there to perform the above ? Thanks in advance.

UPDATE :

After the discussion, considering the size is big let down I have modified the code . But how to fill vector table with certain number of NULL values ?I tried the below code but it is not working .

<pre><code>
for(int i =0;i < hashsize;i++){
            table.push_back((doubly *)NULL);
        }

table.insert(table.begin(),hashsize,NULL);
//Both give invalid static_cast from type `int' to type `doubly*'
</code></pre>

ANSWER UPDATE :


    myHashStrKey::table(myHashStrKey::hashsize, static_cast(0));
    myHashStrKey::table(myHashStrKey::hashsize);
    //Above 2 does not work

    for(int i =0;i != myHashStrKey::hashsize;i++){ //lesser than symbol spoils the display
        myHashStrKey::table.push_back((doubly *)NULL);
    }
    //Above works 
    myHashStrKey::table.insert(myHashStrKey::table.begin(),hashsize,((doubly *)NULL));
    //This too works
  • 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-20T07:54:30+00:00Added an answer on May 20, 2026 at 7:54 am

    Variable-length arrays are not supported by the C++ standard. Instead, simply use a std::vector:

    private:
        std::vector<doubly *> table;
    
    ...
    
    myHashStrKey()
        : table(num_elements, NULL)  // Initialises vector
    {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE: Answer #3 ended up working the best. I most likely did something wrong
I am looking at an enum I created in Reflector and there is a
I'm trying to make a sort of game using the HTML5 canvas, JavaScript and
I have an entity named Tour which can have many Agents . I am
The following can be done by step by step, somewhat clumsy way, but I
I have sort of weird situation and I am not sure why it is
Visual Studio raises a error when I place HTML inside the @Using block: >
Currently, db4o does not allow indexing on the contents of collections. What object databases
Good day! I've found this solution here: VS2010 Web Publish command line version of

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.