|
Thanks, but...
The example I gave was straight from: "The C++ Standard Library" by
Nioclai M. Josuttis, so one would like to think it would work.
Changing printWithPrefix()to accept two std::string arguments gives:
for_each( col1.begin(), col1.end(), bind2nd( mem_fun_ref( &Person::printWithPrefix ), "person: ", "abc" ) );
d:\libs\tests\teststl.cpp(71) : error C2784: 'class std::mem_fun_ref_t<_R,_Ty> __cdecl std::mem_fun_ref(_R (__thiscall _Ty::*)(void))' : could not deduce template argument for '<Unknown>' from 'int (__thiscall Person::*)(class std::basic_string<char
,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)'
d:\libs\tests\teststl.cpp(71) : error C2780: 'class std::binder2nd<_Bfn> __cdecl std::bind2nd(const _Bfn &,const _Ty &)' : expects 2 arguments - 3 provided
g:\program files\microsoft visual studio\vc98\include\functional(189) : see declaration of 'bind2nd'
I'm not sure if you are right about bind2nd(), but having not used this before anything is possible. I just tried bind1st to no avail.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
Well, seems to me there are three problems here:- The offending line should be using
mem_fun1_ref :
for_each( col1.begin(), col1.end(), bind2nd( std::mem_fun1_ref( &Person::printWithPrefix ), "person: " ) );
- Even so, the probem doesn't compile due to (what it seems to me) a bug in the STL implementation for VC++:
mem_fun1_ref is defined as returning a std::binary_function<T *, A, R> , when it should return a std::binary_function<T, A, R> !
- The last problem is that
bind2nd passes as its first argument a const reference, which doesn't match with what mem_fun1_ref expects; basically, the standard is broken in this aspect.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for that. Chris Losinger also suggested mem_fun1_ref which I tried, and also found didn't work.
I spent several hours on this earlier today, assuming it was simply my lack of understanding of STL and there had to be an solution.
The example in the book I refered to declares printWithPrefix as:
void printWithPrefix(..) const; but I had to change the return type to int and remove the const to get print() to work.
If anyone has STLPort etc. installed I'd be interested to know if this code works with them.
I'm sure this really should be so hard.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
You might try Boost.Functional[^]. It fixes a number of errors of the standard wiith respect to binders and functional adapters.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
If you add the const back in, it works with STLport (4.5.something - the current version). Note that mem_fun1_ref isn't part of the standard (AFAIR). Single argument member functions are supported (in the Standard & STLPort) through overloading mem_fun_ref.
I'd second Joaquín Muñoz - Boost has a nice substitute for functional that works very nicely...as does most of the rest of Boost . The following line of code is the Boost equivalent of the STL code...the '_1' is a placeholder for the iterator parameter supplied in for_each .
for_each( col1.begin(), col1.end(), boost::bind( &Person::printWithPrefix , _1, "person: " ) );
One other thing you can do with the Boost version - make the parameter to printWithPrefix a const std::string& - Boost works around the C++ rule that you can't take a reference to a reference.
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Hi Stuart,
Thanks for that. Am I right in assuming that STLPort is the STL implementation of choice these days? I've downloaded it, but haven't got as far as building the library yet.
There is no doubt that Boost has some good stuff in it. I've just started using boost::scoped_ptr because VC auto_ptr doesn't have reset(), which I find quite astonishing. scoped_ptr is a better choice any way as it turns out.
Will using Boost functional as per your example work with VC STL or is this only with STLPort?
I'm also using LibSigC++ which I can do nothing but highly recomend. And as just recently noted on CP, Boost has just released their own implementation of signals and slots, which I look forward to trying when a get some spare time.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
Well...it's my implementation of choice . I use it for VC6 because it's more standard compliant than the one that ships with VC6 and also has some nice extra features (rope s and hash_map s, for example - rope s are nice for incrementally building up a big (Mb) string - three times faster than strings in some basic benchmarks I did). One other very nice feature is the debug version - iterators that tell you when you're using them incorrectly!!! Told me off about several things in my code!
The main downside is that it seems to pull more dross than the Dunkumware STL implementation because of the way it initialises it's iostream s (but, on the other hand, their fstream implementation uses memory mapping, which should boost (no pun) performance). That may not be true - I tend to statically link to STLport, but dynamically link to the VC6 STL, because of the availability of the respective DLLs.
As for Boost.functions , AFAIR, they work with both STL implementations. I've not used their signals yet - I rolled my own version about 18 months ago, which I'm still using.
Stuart Dootson
'How can you give a f**k when nothing seems to matter at all' - Mission of Burma, Vs
|
|
|
|
|
I define this data in header file.
---------------------------------------------------
#define Hash[0] "208803DD4D"
#define Hash[1] "146DB1CB1C"
#define Hash[2] "26D2199CFA"
#define Hash[3] "7CAFF3D504"
#define Hash[4] "6C40AB0E42"
#define Hash[5] "1E1D7486BE"
#define Hash[6] "A03E54D487"
#define Hash[7] "7ACC08F3F7"
#define Hash[8] "6B0133E813"
#define Hash[9] "114CFE0C12"
---------------------------------------------------
when I compile there is error message show
"error C2008: '[' : unexpected in macro definition"
If you know how to declare these array in header file,please tell me. Thank you.
|
|
|
|
|
YOu can't do it with #define. You should declare it as a const array, like this, using a CString or an STL string:
const CStirng Hash[] =
{
"data",
"data",
...
};
Or you could use char * in a similar way (I believe... no compiler with me at the moment so the syntax might not be 100% correct... ):
const char **hash =
{
"data",
"data",
"data",
...
};
Even a broken clock is right twice a day.
|
|
|
|
|
define it as:
<br />
char *Hash[10] = <br />
{"208803DD4D",<br />
"146DB1CB1C",<br />
"26D2199CFA",<br />
"7CAFF3D504",<br />
"6C40AB0E42",<br />
"1E1D7486BE",<br />
"A03E54D487",<br />
"7ACC08F3F7",<br />
"7ACC08F3F7",<br />
"6B0133E813",<br />
"114CFE0C12"<br />
};<br />
|
|
|
|
|
That won't work. Lose the *
Signature space for rent. Apply by email to....
|
|
|
|
|
|
How to convert float numbers to a CString class or a char type?
And how to convert a char type to a float number?
Thks in advance!
Appstmd
http://www.appstmd.com
|
|
|
|
|
|
|
Look up CString::Format
Jason Henderson start page articles "If you are going through hell, keep going." - Sir Winston Churchill
|
|
|
|
|
use std::ostringstream .
You use its << operator to shift the number in, and get the textual representation of it via its str() memberfunction.
|
|
|
|
|
anyone can kindly help me with this? thx a lot in advance.
i created a subclass from CListCtrl named uiCtrlListCtrl.
in the new class i implemented a message handler for OnLButtonDown, but i don't know how to get the Control List's Identifier inside the handler of this message.
the message handler is as below:
void caauiCtrlListCtrl::OnLButtonDown(UINT nFlags, CPoint point){
...
CWnd* pwndParent = GetParent();
pwndParent->SendMessage(UI_WM_LBTNDOWN, ?what should i put here for the list control's ID? );
...
}
|
|
|
|
|
I guess this should have to work:
pwndParent->SendMessage(UI_WM_LBTNDOWN, ::GetWindowLong(m_hWnd,GWL_ID));
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
it works! really appreciate your help!
i just found another means, but not so simple as this way.
i added one variable and then use it to store the control id from calling GetDlgCtrlID().
int nIdFrom;
nIdFrom = GetDlgCtrlID();
pwndParent->SendMessage(UI_WM_LBTNDOWN, (WPARAM)nIdFrom);
|
|
|
|
|
Hi Friends
I want the check the class name of the window being created with a given string. Or to write all class names to a file. I am using WH_CBT Hook..
But the following code is giving a memory cant read error. Any idea?
Regads.
Gaurika.
LRESULT CALLBACK FindToolbarProc(int nCode, WPARAM wParam, LPARAM lParam)
{
// watch window creation:
if (nCode == HCBT_CREATEWND)
{
CBT_CREATEWND* pcw = (CBT_CREATEWND*)lParam;
// watch for Notepad creation, set toolbar name
if (pcw->lpcs->lpszClass &&
0 != strstr(pcw->lpcs->lpszClass, "Notepad")) //
{
Beep(1000,100); // Just to Identify…..
}
}
return CallNextHookEx(g_hkCBT, nCode, wParam, lParam);
}
Gaurika Wijeratne. // www.gaurika.com
|
|
|
|
|
Can you use the typeID operator available with the RTTI?
Pankaj
Without struggle, there is no progress
|
|
|
|
|
Not with this particular problem he can't...
He wants the MS windows window class string, not a window object class name.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I don't know exactly and i'm to lazy to make a Q and D app to test yer code, but i'll offer my suggestion.
LRESULT CALLBACK FindToolbarProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HCBT_CREATEWND)
{
CBT_CREATEWND* pcw = (CBT_CREATEWND*)lParam;
ASSERT(pcw);
if(strcmp(pcw->lpcs->lpszClass, "Notepad") == 0)
Beep(1000,100);
}
return CallNextHookEx(g_hkCBT, nCode, wParam, lParam);
}
Are you sure that pointer is valid...?
Also I dunno if this has anything to do with it...but...perhaps ReadProcessMemory() should be used...? I'm thinking because a windows window class is probably stored locally to the process that created it so trying to read it using c-style pointers might cause memory read errors...??? I have no idea other than that...
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hi,
I have a threads problem and here it is:
I am developing a program that will draw the graphic of a mathematical function but I want the draw to be done in other thread because for example if the multiplaier(the for is decreasing 'x' with 1/multiplaier) is too big, the program will draw the graphic slowly, and on every WM_PAINT message to my control the graphic has to be redrawn, and so if the user moves the window or whatever he doest to it, he will have to wait until the graphic is completly drawn, so I wanna make another thread to do this, but I have problem with the ThreadProc function:
I made a struct where all the parameters for the drawing are set:
<br />
typedef struct _DRAWERSUB {<br />
HDC dc;<br />
CRichEditCtrl *ctrlResults;<br />
char * strFormula;<br />
char * strX;<br />
float nMultip;<br />
int cx;<br />
int cy;<br />
double dPrecision;<br />
BOOL bPrecision;<br />
int nRootsFound;<br />
double nDivs;<br />
BOOL bCalc;<br />
} DRAWERSUB, *LPDRAWERSUB;<br />
this is the struct.
I initialize it in a function called by WM_PAINT as:
<br />
DRAWERSUB dwsub;<br />
dwsub.strFormula = (LPTSTR)(LPCTSTR)m_strFormula;<br />
dwsub.strX = (LPTSTR)(LPCTSTR)m_strX;<br />
dwsub.dc = dc->GetSafeHdc();<br />
dwsub.nDivs = m_nDivisions;<br />
dwsub.nMultip = m_nMultip;<br />
dwsub.cx = cx;dwsub.cy = cy;<br />
dwsub.bCalc = m_bCalc;<br />
dwsub.bPrecision = m_bPrecission;<br />
dwsub.dPrecision = precision;<br />
m_trGraphicDrawer = AfxBeginThread(GraphicDrawerSub,&dwsub);
and this is the code for the ThreadProc:
<br />
UINT CGraphicFunc::GraphicDrawerSub(LPVOID pParam)<br />
{<br />
LPDRAWERSUB dwsub = (LPDRAWERSUB)pParam;<br />
CString strFormula((LPCTSTR)(LPTSTR)dwsub->strFormula), strX((LPCTSTR)(LPTSTR)dwsub->strX);<br />
HDC hDC = dwsub->dc;<br />
double nDivs = dwsub->nDivs;<br />
float nMultip = dwsub->nMultip;<br />
int cx = dwsub->cx, cy = dwsub->cy;<br />
double dPrecision = dwsub->dPrecision;<br />
BOOL bPrecision = dwsub->bPrecision;<br />
BOOL bCalc = dwsub->bCalc;<br />
.....<br />
}<br />
but every time the ThreadProc is called, strFormula, strX and every value from it, has different value, sometimes the hDC is valid and sometimes it isn't...strFormula sometimes is "" and strX is something like this:
"U‹ìQƒeü"
What can I do for rapairing this problem???
I am not good at threads and I almost no experience with them ...
Thanks.
|
|
|
|
|