Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. STL and member functions ???

STL and member functions ???

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++comdebuggingtools
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #1

    I'm working on a trace utility, mainly to extend my knowledge of IOStreams and STL. I have a map to keep track of a number of edit windows, which all take the same position and are sown based on a tab control. map m_TraceMap; Now, I hide all my windows before showing the one selected, like this: void HideWindow(std::pair p) { CTraceWnd * pWnd = p.second; pWnd->ShowWindow(SW_HIDE); } void CTabView::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) { std::for_each(m_TraceMap.begin(), m_TraceMap.end(), HideWindow); // etc, etc. Now I have two questions. 1. How can I make HideWindow a member function of CTabView ? I've tried mem_funxxx stuff, to no avail, and spent a good amount of time reading 'Generic Programming and the STL', also without any success. 2. Better yet, is there a way I can call ShowWindow(SW_HIDE) directly, OR add a HideWindow function that does this to CTraceWnd, and call that ? Thanks to anyone who answers. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

    Sonork ID 100.10002:MeanManOz

    I live in Bob's HungOut now

    T A 2 Replies Last reply
    0
    • C Christian Graus

      I'm working on a trace utility, mainly to extend my knowledge of IOStreams and STL. I have a map to keep track of a number of edit windows, which all take the same position and are sown based on a tab control. map m_TraceMap; Now, I hide all my windows before showing the one selected, like this: void HideWindow(std::pair p) { CTraceWnd * pWnd = p.second; pWnd->ShowWindow(SW_HIDE); } void CTabView::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) { std::for_each(m_TraceMap.begin(), m_TraceMap.end(), HideWindow); // etc, etc. Now I have two questions. 1. How can I make HideWindow a member function of CTabView ? I've tried mem_funxxx stuff, to no avail, and spent a good amount of time reading 'Generic Programming and the STL', also without any success. 2. Better yet, is there a way I can call ShowWindow(SW_HIDE) directly, OR add a HideWindow function that does this to CTraceWnd, and call that ? Thanks to anyone who answers. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

      Sonork ID 100.10002:MeanManOz

      I live in Bob's HungOut now

      T Offline
      T Offline
      Todd Smith
      wrote on last edited by
      #2

      class MyClass : public CTabView { public: MyClass() {} void HideWindow() { CTabView::ShowWindow(SW_SHOW); }; }; // this seems like it should be a template of some kind void HideWindow(const std::pair& v) { MyClass& blah = const_cast(v.second); blah.HideWindow(); } void main() { std::map blah; std::for_each(blah.begin(), blah.end(), HideWindow); }

      C 2 Replies Last reply
      0
      • T Todd Smith

        class MyClass : public CTabView { public: MyClass() {} void HideWindow() { CTabView::ShowWindow(SW_SHOW); }; }; // this seems like it should be a template of some kind void HideWindow(const std::pair& v) { MyClass& blah = const_cast(v.second); blah.HideWindow(); } void main() { std::map blah; std::for_each(blah.begin(), blah.end(), HideWindow); }

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        Thanks, I'm sure this will work, and the way I'm doing it now works, too, but I want to get rid of the global function altogether and replace it with a member function, either of the class held in the second part of the pair, or in the class calling the function. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

        Sonork ID 100.10002:MeanManOz

        I live in Bob's HungOut now

        1 Reply Last reply
        0
        • T Todd Smith

          class MyClass : public CTabView { public: MyClass() {} void HideWindow() { CTabView::ShowWindow(SW_SHOW); }; }; // this seems like it should be a template of some kind void HideWindow(const std::pair& v) { MyClass& blah = const_cast(v.second); blah.HideWindow(); } void main() { std::map blah; std::for_each(blah.begin(), blah.end(), HideWindow); }

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          void CTabView::HideWindow(std::pair p) { CTraceWnd * pWnd = p.second; pWnd->ShowWindow(SW_HIDE); } void CTabView::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) { std::for_each(m_TraceMap.begin(), m_TraceMap.end(), std::mem_fun_ref(&CTabView::HideWindow)); but I get this error: 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 '' from 'void (__thiscall CTabView::*)(struct std::p air)' I thought maybe mem_fun1_ref, but things just got worse. I tried adding the function to CTraceWnd, but that was worse again.... Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

          Sonork ID 100.10002:MeanManOz

          I live in Bob's HungOut now

          T 1 Reply Last reply
          0
          • C Christian Graus

            I'm working on a trace utility, mainly to extend my knowledge of IOStreams and STL. I have a map to keep track of a number of edit windows, which all take the same position and are sown based on a tab control. map m_TraceMap; Now, I hide all my windows before showing the one selected, like this: void HideWindow(std::pair p) { CTraceWnd * pWnd = p.second; pWnd->ShowWindow(SW_HIDE); } void CTabView::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) { std::for_each(m_TraceMap.begin(), m_TraceMap.end(), HideWindow); // etc, etc. Now I have two questions. 1. How can I make HideWindow a member function of CTabView ? I've tried mem_funxxx stuff, to no avail, and spent a good amount of time reading 'Generic Programming and the STL', also without any success. 2. Better yet, is there a way I can call ShowWindow(SW_HIDE) directly, OR add a HideWindow function that does this to CTraceWnd, and call that ? Thanks to anyone who answers. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

            Sonork ID 100.10002:MeanManOz

            I live in Bob's HungOut now

            A Offline
            A Offline
            Alexander Berthold
            wrote on last edited by
            #5

            Create a from std::unary_function derived helper class then it should work. For map for_each functors, it should look like this, remember the first pair argument must be const (i think). I assume your maps' pairs' first argument is an int. class hidewindow_functor : public std::unary_function< std::pair<int const,CWnd*>, void> { public: void operator() (std::pair<int const,CWnd*>& target) const { target.second->ShowWindow(SW_HIDE); } }; Cheers, Alexander Berthold

            C 1 Reply Last reply
            0
            • C Christian Graus

              void CTabView::HideWindow(std::pair p) { CTraceWnd * pWnd = p.second; pWnd->ShowWindow(SW_HIDE); } void CTabView::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) { std::for_each(m_TraceMap.begin(), m_TraceMap.end(), std::mem_fun_ref(&CTabView::HideWindow)); but I get this error: 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 '' from 'void (__thiscall CTabView::*)(struct std::p air)' I thought maybe mem_fun1_ref, but things just got worse. I tried adding the function to CTraceWnd, but that was worse again.... Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

              Sonork ID 100.10002:MeanManOz

              I live in Bob's HungOut now

              T Offline
              T Offline
              Tim Smith
              wrote on last edited by
              #6

              Try making a "void HideWindow ()" method in CTraceWnd. Then "std::mem_fun_ref (CTraceWnd::HideWindow)" should work. Tim Smith Descartes Systems Sciences, Inc.

              C 1 Reply Last reply
              0
              • T Tim Smith

                Try making a "void HideWindow ()" method in CTraceWnd. Then "std::mem_fun_ref (CTraceWnd::HideWindow)" should work. Tim Smith Descartes Systems Sciences, Inc.

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                I had done that previously, and I get this: void CTabView::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) { std::for_each(m_TraceMap.begin(), m_TraceMap.end(), std::mem_fun_ref(CTraceWnd::HideWindow)); void CTraceWnd::HideWindow(std::pair p) { p.second->ShowWindow(SW_HIDE); } 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 '' from 'void (__thiscall CTraceWnd::*)(struct std:: pair)' Tried mem_fun1_ref as well. I don't think this can work as I need to pull second out of the pair first, which requires some non-standard stuff found in STLPort, etc. I will install STLPort tonight. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

                Sonork ID 100.10002:MeanManOz

                I live in Bob's HungOut now

                1 Reply Last reply
                0
                • A Alexander Berthold

                  Create a from std::unary_function derived helper class then it should work. For map for_each functors, it should look like this, remember the first pair argument must be const (i think). I assume your maps' pairs' first argument is an int. class hidewindow_functor : public std::unary_function< std::pair<int const,CWnd*>, void> { public: void operator() (std::pair<int const,CWnd*>& target) const { target.second->ShowWindow(SW_HIDE); } }; Cheers, Alexander Berthold

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  Thanks - although not quite what I was after, I'm now convinced I need some non standard STL stuff from STLPort to make it work the way I want. However, it only works if I make CWnd above CTraceWnd, can you tell me why STL cannot do the cast ? Thanks. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

                  Sonork ID 100.10002:MeanManOz

                  I live in Bob's HungOut now

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups