Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
delete[] p or delete[] *p
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Paul, post: 4200434"] 1. int i; int* pi = &i; What array are we talking about here? In other words, if pi __is__ a pointer to an array of T, then why is the above possible and correct, even? Because C type system is broken or because your claim is broken? xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx The only thing broken is your brain. Obviously the above pointer doesn't point to an array but the same type of pointer below points o an array: int* p_to_array = new int[5]; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 2. int a[3]; int (*pa)[3] = &a; if p __is__ a pointer to array, what is pa? I believe language disagrees with your claim here. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx pa is also a pointer to an array, its just a different type of pointer. pa is the same type of pointer generally used to point to a 2d array. If pa is dereferneced it returns a 1dim array, thus obeying the C++ language rules for arrays. Your use of the &addressof operator is simply creating a pointer that needs to be dereferenced twice to access the array. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 3. int a[3]; int* p = a; Here, we __commonly say__ that p is a pointer to array. But p is __not__ a pointer to array. Instead, e.g. in "int (pa)[3] = &a;", __pa__ is a pointer to array. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx No p is a pointer to an array of 3 ints, that's why we commonly say .it's a pointer to an array. xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Your claim leads to confusion and errors, and is possibly the reason why you want to write code such as that you've shown us here (downright wrong, like Base/Derived example, very unsafe like template<> foo example, and also at odds with what's prescribed, like your very first example). xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx You certainly seem confused, I'm not. A pointer to a 1d array is dereferenced once to return an element: p_arr_1d[0]; A pointer to a 2d array is dereferneced twice to return an element: p_arr_2d[0][0]; With your theory you think a pointer to a 1d array is like so : int (*p)[5] = &a_1d_array; All this does it make a pointer which has another level of indircetion and would unneccessarily need to be dereferenced twice to access the array. (*p)[0]; You, and many others, are obviously unable to garsp the simple facts of how pointers to arrays work in C++ . For this reason and many other unreasonable arguments I have seen in these forums , I am going to try and stop reading this shit and eventually I will have fully plonked this well and trully disgusting newsgroup that is full of arseholes know-it-alls who don't have a clue, but they actually think they are expert programmers. Clueless arseholes with no personailty, only bad personality, and too much time to spend reading documents they dont understand. Just look at your point 1 to see how much of an unreasonable idiotic arsehole you are. What goes through your idiot brain? xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
delete[] p or delete[] *p
Top