Why can't I...

Is it really possible to do this...

1
2
3
4
for(int i=0;i<no_of_people_to_add;i++)
    {
        node *temp[i]=new node;
    }

Where:
no_of_people_to_add is an int, which contains a value based on the user's input

I think "NO!!!", so how do I do it. I actually want to make temp an array of pointer to type node, based on users input?!?

-Working with linked lists
Last edited on
closed account (zb0S216C)
Yes, you can do that, but your use of temp and new is suspicious. Is there something wrong with std::vector?

Wazzak
checking that! thanks!!
Can I have an example code?
closed account (zb0S216C)
Of std::vector? Sure:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <vector>

int main()
{
    std::vector<int> my_ints; // Contains nothing.

    // Add 1 "int" to "my_ints" and give it the value 50...
    my_ints.push_back(50);

    // Get the first element of "my_int"...
    int temp(my_ints.at(0)); // Same as "my_ints[0]"

    return(0);
}

See here: http://www.cplusplus.com/reference/stl/vector/

Wazzak
Last edited on
Topic archived. No new replies allowed.