Why is this illegal, all are addresses

people say
 
vector<string> **pv=new vector<string>[10]


is illegal. But why?

the left side defined pv as an pointer which point to a pointer which point to a string vector. so pv is an address.

the right side give an address of a 10-D array, whose elements are string vectors.

both side are address, why cannot establish?
¿why don't just read the compile error? The types are different, one is T** and the other T*

Also, ¿why are you doing that?
To add to what ne555 said, why are you doing that?

Both sides are address, but the left is the address of an address of an object and the right is an array of objects. They're different types, so the compiler has correctly stopped from making a mistake.
closed account (zb0S216C)
northfly wrote:
vector<string> **pv=new vector<string>[10] (sic)

Here's why it's illegal:

new returns a pointer to the first element of an allocated region of the specified type and size. The pointer on the left-hand side acquires ownership of that memory, then the pointer returned by new is destroyed.

That said, when pv is assigned to the address of the pointer returned by new (which you don't do anyway), you're taking the address of a temporary pointer that no longer exists.

Wazzak
Topic archived. No new replies allowed.