Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
c++ pointers with arrays
Name: Martyn999 Date: November 9, 2006 at 03:11:20 Pacific OS: Windows XP Pro SP1 CPU/Ram: Athlon64 3500+ / 1GB
Comment:
I have a base class Shape, then 3 more which inherit from this: Square, Triangle and Circle. I have an array of Triangle objects, and am working with virtual functions using polymorphism. If I make a pointer to the first element of the Triangle array, I can use ptr->Draw(); to display this. To get to the second element I can use ptr++;, then the draw method applies to the second element.
My problem is that I need to make the pointer of type Shape, then set it to point the the first element of the Triangle array. This first one works, but when I use ptr++; to move to the second element it becomes a pointer to some address which I can only imagine would be the next array of Shapes, so basically it doesn't advance the Triangle array. Is there any way to be able to loop through each element in Triangle apart from making a pointer array to each element?
Summary: In C, how can u read values into an array (ex. array[row][col]) and exit from the for loop right after the user types 0 in the 1st column of any row? Can someone give me some sample code because I tr...
Summary: Straight forward multi-dimensional arrays are not possible with malloc because, for example with a hard-coded 2 dimensional array, the compiler knows the number of columns in each row and can therefor...
Summary: Is it possible to declare a pointer to an array of character pointers? Here is the context: char *colors[] = {"purple", "red", "blue", "green"}; char *names[] = {"Jim", "Bob", "David", "Tom"}; void fu...