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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How do I access / use base class method declared private?

How do I access / use base class method declared private?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
6 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.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    I like to use HitTest to identify a splitter pane via mouse. It is a virtual function / method declared "protected" in base CSplitterWnd class. I have never used this and have no idea what is the correct syntax. I would appreciate any help. Vaclav Ok I build an override function with instance of base class, but still cannot figure out how to get pass the "protected" virtual function.

    Richard Andrew x64R _ 2 Replies Last reply
    0
    • V Vaclav_

      I like to use HitTest to identify a splitter pane via mouse. It is a virtual function / method declared "protected" in base CSplitterWnd class. I have never used this and have no idea what is the correct syntax. I would appreciate any help. Vaclav Ok I build an override function with instance of base class, but still cannot figure out how to get pass the "protected" virtual function.

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      Isn't it:

      CSplitterWnd::HitTest(blah, blah);

      The difficult we do right away... ...the impossible takes slightly longer.

      V 1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        Isn't it:

        CSplitterWnd::HitTest(blah, blah);

        The difficult we do right away... ...the impossible takes slightly longer.

        V Offline
        V Offline
        Vaclav_
        wrote on last edited by
        #3

        Nope, cannot access function declared protected.

        F 1 Reply Last reply
        0
        • V Vaclav_

          Nope, cannot access function declared protected.

          F Offline
          F Offline
          Freak30
          wrote on last edited by
          #4

          If you (publicly) derive from the base class, you should have access to all protected members of the base class from your derived class. So the start of your class definiton should look like class MyClass : public CSplitterWnd If you have a protected in this line instead of the public, it will not work. Also the access will only be available from your derived class, not from any other class that uses an instance of the derived class.

          The good thing about pessimism is, that you are always either right or pleasently surprised.

          V 1 Reply Last reply
          0
          • V Vaclav_

            I like to use HitTest to identify a splitter pane via mouse. It is a virtual function / method declared "protected" in base CSplitterWnd class. I have never used this and have no idea what is the correct syntax. I would appreciate any help. Vaclav Ok I build an override function with instance of base class, but still cannot figure out how to get pass the "protected" virtual function.

            _ Offline
            _ Offline
            _Superman_
            wrote on last edited by
            #5

            HitTest is not a function that you call using the instance of a class. Rather, it is a virtual function that you can override, so that the MFC framework can call it using a base class object reference. There are other similar virtual functions like OnInitDialog for example. From the HitTest override, you simply check the point passed in and return one of the HTXXX values. For example, to move a dialog by clicking and dragging anywhere on it, just like its caption, you simply return HTCAPTION from the overridden HitTest method of the CDialog derived class. This is how it will be called internally -

            // Imagine this to be the framework code
            class CMyFramework
            {
            public:
            void foo() { this->bar(); }

            protected:
            virtual void bar() { }
            };

            // Here are your overrides
            class COne : public CMyFramework { };
            class CTwo : public COne { };
            // Derive to your hearts content like MFC does.

            // Finally
            class CTen : public CNine
            {
            protected:
            virtual void bar()
            {
            cout << "MyBar" << endl;
            }
            };

            The framework simply calls the CMyFramework::foo method and it will call CTen::bar because it is virtual.

            «_Superman_»  _I love work. It gives me something to do between weekends.

            _Microsoft MVP (Visual C++) (October 2009 - September 2013)

            Polymorphism in C

            1 Reply Last reply
            0
            • F Freak30

              If you (publicly) derive from the base class, you should have access to all protected members of the base class from your derived class. So the start of your class definiton should look like class MyClass : public CSplitterWnd If you have a protected in this line instead of the public, it will not work. Also the access will only be available from your derived class, not from any other class that uses an instance of the derived class.

              The good thing about pessimism is, that you are always either right or pleasently surprised.

              V Offline
              V Offline
              Vaclav_
              wrote on last edited by
              #6

              Thanks, you found the problem. My splitter is derived from CMDIChildWnd. I am not sure why, but it works as a splitter OK. And since I am still using VC6.0 MFC multiple inheritance should work, but that is a ton of work to remove all the ambiguities... I was going to use HitTest to maximize selected pane, so I better stick with moving splitter bars.

              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