|
mem_fun_ref and relatives have severe design flaws as for the const ness of their arguments, so you'll have to write some code yourself. The basic idea is to have an object presenting a normalized interface to for_each that forwards the call to the appropriate foo object and method. Just like this:
class foo
{
void foo()
{
std::for_each(vec.begin(),vec.end(),bar_stub(this));
}
void bar(int val)
{
...
}
struct bar_stub
{
bar_stub(foo* f):f(f){}
void operator(int val)
{
f->bar(val);
}
private:
foo* f;
};
};
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
The problem is not mem_fun_ref, but the implimentation in VC, I thought.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
|
|
|
|
|
Hi Christian! Well, the problem actually lies in bind1st (necessary to bind the 1st argument of mem_fun_ref to the object used,) whose signature is, according to the Standard Template Library Programmer's Guide:
template <class AdaptableBinaryFunction, class T>
binder1st<AdaptableBinaryFunction>
bind1st(const AdaptableBinaryFunction& F, const T& c); The const ness of the second parameter is what causes the problem.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
OK. I read an article in last months CUJ that led me to believe otherwise. I obviously did not read closely enough, or was feeling anti VC after finding out it does not impliment Koenig lookup properly.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
|
|
|
|
|
This time it is not VC++'s fault, but don't worry, we've got still plenty of stuff to blame it for
The bind1st and mem_fun problem is very well known among C++ geeks since long (do a search on the Usenet.) As always, Boost provides a remedy, check its Member Function Adapters section.
PS: Your sig is a real quotation?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
Your sig is a real quotation?
Yup - verbatim
Joaquín M López Muñoz wrote:
As always, Boost provides a remedy
Yes, the article in CUJ linked to Boost ( not surprisingly, I'd have expected them to have a fix ), then somewhat redundantly provided their own. They wisely suggested people use the Boost one over theirs, but why include it then ?
Still, CUJ lost credibility in my eyes when Herb Sutter provided a glowing review of a book they had previously reviewed already, a book written by someone he happens to be coauthoring a book with at the moment. That it's a good book does not stop that from sucking IMO.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
|
|
|
|
|
Maybe (i hope) this is a easy task to preform for most VC++ programmers, but i'm having dificulties in changing this kind of object's backcolor.
Can anyone help me?
Thank for your time!
|
|
|
|
|
|
I checked it, but, maybe because i used to VB, i found it a bit confusing because all the data type and all! Isn't there a easy way to do this?
Thank you!
|
|
|
|
|
Yes, the way that Nish told you. Welcome to the world of real programming languages.
There is most certainly an article on CP that shows you how to do this. Nish probably wrote it.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
|
|
|
|
|
Hello,
In order to display some graphic stats (bars, pies, ...), I integrated a MsChart in a dialog and I works fine. But now, I would like to be able to print this chart, so how can I do this ?
Thanks in advance.
DD
|
|
|
|
|
I dunno if there is some other way, but you could certainly get the DC of the control and pass it to the printer DC.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
|
|
|
|
|
hello,
thanks for answer, but as I am a quite new in VC++, I have to admit that I am not sure to understand your explanation and that I need some more details or even example/part of code.
Thanks
DD
|
|
|
|
|
Do you know how to print at all ? If not, you should probably check out some articles on the site. That's a lot of info to impart in a forum post.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
|
|
|
|
|
I can't say I am an expert in printing (for sure), I have just printed the content of a RichEditText control, so I have the basis to do it.
But there are a lot of ways to perform a print depending of a lot of facts (control type, etc).
I found a way to do it using the clipboard, but is there any other simplier way ?
DD
|
|
|
|
|
I did this awhile back. I tried the grab the DC approach and had limited success. I ended up using the clipboard approach, the control copies a WMF image to the clipboard. I really disliked this approach but it seemed to be the prescribed approach. If you want send me an e-mail to nwilhelmi@attbi.com and I can send you some code when I get home. The app was done with WTL so it will be WIN32api based and not MFC based.
NW
|
|
|
|
|
I have build a class,derived from CEdit, that validates Edit box data as the user enters it. Is there a way to use a CEdit derived class to validate Data changes made to a combo box? Or will I have to build a class derived from CCombo?
|
|
|
|
|
Damn! I can't remember it, but there was some way to subclass the edit box of a combo! I'll look for it, but I bet someone else will answer ya before I can dig it up
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Buy it, read it and admire me
|
|
|
|
|
|
A million thanks. I was just about to dive into deriving a my own combobox class and then subclassing my edit control in my new combobox ctrl. This is much 'classier'
|
|
|
|
|
Hi,
I know we can modify a resource using updateresource
function... but its like i have a string in
CString and i want to copy that to a resource
table entry...
Does anyone know how to do that
Sameer
|
|
|
|
|
String resources are weird. Strings are stored in blocks of 16. IDs 0-15 are block 0, 16-31 are block 1, etc. So block# == ID >> 4. Use the block # to load the resource (with Find/Load/LockResource APIs). Once you get the block loaded, the format of the block should be obvious (Unicode strings, length-prefixed).
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
I've tried my own little replica of Chris' Creating Custom Controls, but whenever I add it to my project, the program simply fails to load, with no error or display of any kind. Has anybody had this problem, and how did they resolve it? I don't know where in the source my problem could be, and I shouldn't post the whole thing.
Thanks,
- Jason
(SonorkID 100.611)
In the beginning, teachers taught the 5 W's: who, what, where, when, why. Now it's just a big damn G
|
|
|
|
|
I've been there. It was a while ago, but I think it had to do with the message pump.
Make sure that you're handling your messages to the custom control correctly.
Hugo
|
|
|
|
|
Ok. Thanks very much for the reply and the help. I'll look at the messages and go from there.
- Jason
(SonorkID 100.611)
In the beginning, teachers taught the 5 W's: who, what, where, when, why. Now it's just a big damn G
|
|
|
|