STL Vector Problem

Started by
17 comments, last by MaulingMonkey 18 years, 10 months ago
Quote:Original post by snk_kid
i know you have already found the problem but i just want to mention something

Quote:Original post by Programmer16
Widget* pCtrl = ((Widget*)pItor);


This is not wright, setting a side the fact that C-style casts are bad for [grin]


Indeed, this should be done like so:
Widget* pCtrl = &*pItor;

Widget** ppCtrl = &*pItor;
or:
Widget&* pCtrl = *pItor;
or:
Widget* pCtrl = *pItor;

Type and const-safe without any casts too!!! :-).

[Edited by - MaulingMonkey on June 9, 2005 5:07:32 PM]
Advertisement
I thought I was doing that wrong, but it seems to work fine (I'm still going to change it, because I know that just because something works once doesn't mean it always will). Also, I wanted to use for_each(), but I didn't know what header it was in.

Edit: I can't get for_each() to work (I think its because I need to pass an HDC to it Render()).

Thanks guys!
Quote:Original post by MaulingMonkey
Indeed, this should be done like so:
Widget* pCtrl = &*pItor;


Ah but he has a vector of pointer to Widget [wink]

either:

Widget* pCtrl = *pItor;


or if he wants to actually modify the original value stored in the vec.

Widget*& pCtrl = *pItor;


Quote:Original post by Programmer16
I didn't know what header it was in.


Handy reference here even if its not 100% correct.
Quote:Original post by Programmer16
Okay, I am really sorry for bothing everybody. Its seems that there isn't anything wrong with my STL (as far as I know). I've never really used Win32 for graphics and I guess I'm only getting WM_PAINT message once. Does anybody know how I fix this?

I believe the typical method is to use some form of a timer or loop to continually tell Windows to repaint your window (as in send you a WM_PAINT message), by using either UpdateWindow() or InvalidateRect().

An easy way to set up a timer would be with SetTimer(). This will send a WM_TIMER message to your window at the (approximately) appropriate times, at which point you'd call one of those two functions above. It's not the most accurate thing in the world time-wise, but it's good to get the basic functionality working. A better timing mechanism can be added later.

And as a couple of side notes, I can't believe I missed that iterator/pointer thingy, and I don't accept your apology for asking questions when the problem was elsewhere. You shouldn't be apologizing to begin with. [smile]
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
Quote:Original post by Programmer16
Edit: I can't get for_each() to work (I think its because I need to pass an HDC to it Render()).


Sorry only glanced at the code before [grin]

#include <algorithm>  // for_each#include <functional> // bind2nd, mem_funstd::for_each(g_Controls.begin(), g_Controls.end(),              std::bind2nd(std::mem_fun(&widget::render), Paint.hdc));


Its times like these C++ can do with a boost [grin].
Original post by snk_kid
Quote:Original post by Programmer16
Its times like these C++ can do with a boost [grin].

Ah, what a coincidence, I just downloaded this.

Edit:
Ok, does anybody know where I can find some boost tutorials? I read the documents, but it doesn't really have any examples (that I can find).

Thanks!

[Edited by - Programmer16 on June 9, 2005 5:51:27 PM]
Original post by Programmer16
Quote:Original post by snk_kid
Quote:Original post by Programmer16
Its times like these C++ can do with a boost [grin].

Ah, what a coincidence, I just downloaded this.

Edit:
Ok, does anybody know where I can find some boost tutorials? I read the documents, but it doesn't really have any examples (that I can find).

Thanks!


Any specific part(s) of boost? I've found examples most of the time, just well hidden :-).
Quote:Original post by MaulingMonkey
Any specific part(s) of boost? I've found examples most of the time, just well hidden :-).


Well, I've found some of them (hidden, as you said), but after actually trying to use it, boost seems to actually work like it shoud (so I've been able to figure it out for the most part).

Thanks for all of your help everybody!

Quote:Original post by snk_kid
Quote:Original post by MaulingMonkey
Indeed, this should be done like so:
Widget* pCtrl = &*pItor;


Ah but he has a vector of pointer to Widget [wink]


TOTALLY need to learn to read here. I'll fix that :3.

This topic is closed to new replies.

Advertisement