472,142 Members | 1,276 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,142 software developers and data experts.

dynamically allocated array of pointers

hello :) I need to make a dynamically allocated array of pointers, using a .hpp and .cpp file; how do I accomplish this? I think I know how to make an array of pointers, and I know how to make a dynamically allocated array, but I am lost as to how to put the two together...

Any help would be appreciated :)
Nov 1 '06 #1
4 6191
9,065 Expert Mod 8TB
Right make a dynamic array of ints

Now everywhere you have "int" replace it with "char *" (or whatever pointer type you are using) and you will have your result.

Post it here and we will check it for you.
Nov 1 '06 #2
in shapeManager.hpp:

shape** shapes;

in shapeManager.cpp:

shapes = new shape*[10];

Nov 1 '06 #3
9,065 Expert Mod 8TB
yes, shapes will point to an array of 10 shape * pointers.

And the moral is don't get hung up on the word "pointer", just because everyone says they are hard and complicated doesn't mean they are, they are just another type of variable :D
Nov 1 '06 #4
9,065 Expert Mod 8TB
1 minor point though, if you put shape **shapes into shapeManager.hpp you will get a copy of it in every cpp file you include shapeManager.hpp into and this will cause a link error of multiply defined symbols.

You shouldn't define data in header files, only declare it extern.


shapeManger.hpp contains

extern shape **shapes; // Declares the variable shapes

shapeManger.hpp contains

shape **shapes; // Defines the variable shapes (actually reserves memory)
Nov 1 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

14 posts views Thread by Peter Olcott | last post: by
7 posts views Thread by masood.iqbal | last post: by
7 posts views Thread by Fabian Wauthier | last post: by
6 posts views Thread by bwaichu | last post: by
3 posts views Thread by Jinkuzo | last post: by
7 posts views Thread by Serpent | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.