std::vector

Started by
16 comments, last by Zoot 21 years, 8 months ago
*Sigh* I understand where your confusion comes from, but let me re-repost my example:

CPolygon **z = &a[0];
a[0] = NULL;

Then, *z == NULL,

So... *z can be == NULL. I admit that it wasn''t clear in my last post.

Cédric
Advertisement
quote:Original post by Zoot
I was playing with vectors last night... and why isn´t z == NULL?

because the computer isn''t clairsentient?
Somewhere you have to set z to null, if you want it to be null.

- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
quote:Original post by cedricl
*Sigh* I understand where your confusion comes from, but let me re-repost my example:

CPolygon **z = &a[0];
a[0] = NULL;

Then, *z == NULL,

So... *z can be == NULL. I admit that it wasn''t clear in my last post.

Cédric


when i do:
CPolygon **z = &a[0];
a[0] = NULL;

Then: z =! NULL
GSACP: GameDev Society Against Crap PostingTo join: Put these lines in your signature and don't post crap!
quote:Original post by Magmai Kai Holmlor
Original post by Zoot
I was playing with vectors last night... and why isn´t z == NULL?

because the computer isn't clairsentient?
Somewhere you have to set z to null, if you want it to be null.



I want z to be the same as a[0]....

[edited by - Zoot on August 19, 2002 9:46:50 AM]
GSACP: GameDev Society Against Crap PostingTo join: Put these lines in your signature and don't post crap!
quote:Original post by Zoot
I want z to be the same as a[0]....


Sounds like you want a reference to pointer.


    std::vector<CPolygon *> a;a.push_back(new CPolygon);a[0]->v1 = vector(0,0,1);CPolygon *&z = a[0];delete a[0];a[0] = NULL;// Now z is NULL  


Whatever you do to a[0], the same thing will happen to z because
z is a reference (alias to a[0]).


Kami no Itte ga ore ni zettai naru!
神はサイコロを振らない!
quote:Original post by tangentz
Original post by Zoot
I want z to be the same as a[0]....


Sounds like you want a reference to pointer.


      std::vector<CPolygon *> a;a.push_back(new CPolygon);a[0]->v1 = vector(0,0,1);CPolygon *&z = a[0];delete a[0];a[0] = NULL;// Now z is NULL    


Whatever you do to a[0], the same thing will happen to z because
z is a reference (alias to a[0]).


Kami no Itte ga ore ni zettai naru!



No, not working.
GSACP: GameDev Society Against Crap PostingTo join: Put these lines in your signature and don't post crap!
quote:Original post by Zoot
No, not working.


Even though I typed the code "cold", I know it works.

It wouldn''t kill you to explain what is "not working",
would it?


Kami no Itte ga ore ni zettai naru!
神はサイコロを振らない!
quote:Original post by Zoot
when i do:
CPolygon **z = &a[0];
a[0] = NULL;

Then: z =! NULL

No, but *z IS equal to NULL (NOT z --- as MKM pointed out, z will NEVER be equal to NULL unless you write it explicitly, or through another pointer). You are dereferencing ONCE a pointer to a pointer to a CPolygon. So, what you get is a pointer to a CPolygon, which CAN be NULL.

And tangentz''s method is the same as mine, except with a reference. It should also work.

Cédric

This topic is closed to new replies.

Advertisement