By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,587 Members | 1,891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,587 IT Pros & Developers. It's quick & easy.

dynamically allocated array of pointers

P: 5
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
Share this Question
Share on Google+
4 Replies

Expert Mod 5K+
P: 8,916
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

P: 5
in shapeManager.hpp:

shape** shapes;

in shapeManager.cpp:

shapes = new shape*[10];

Nov 1 '06 #3

Expert Mod 5K+
P: 8,916
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

Expert Mod 5K+
P: 8,916
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.