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. static and non-static function

static and non-static function

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 6 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.
  • W Offline
    W Offline
    wow9999
    wrote on last edited by
    #1

    Hi all Can a static function call a non-static function inside the same class? or Can a static function call a non-static function in different class? Thanks

    A T R B 4 Replies Last reply
    0
    • W wow9999

      Hi all Can a static function call a non-static function inside the same class? or Can a static function call a non-static function in different class? Thanks

      A Offline
      A Offline
      Alin Negru
      wrote on last edited by
      #2

      wow9999 wrote: Can a static function call a non-static function inside the same class? no or Can a static function call a non-static function in different class? no

      1 Reply Last reply
      0
      • W wow9999

        Hi all Can a static function call a non-static function inside the same class? or Can a static function call a non-static function in different class? Thanks

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

        Yes, no problem. As long as you have the object you wish to invoke the function. Tim Smith I'm going to patent thought. I have yet to see any prior art.

        W 1 Reply Last reply
        0
        • T Tim Smith

          Yes, no problem. As long as you have the object you wish to invoke the function. Tim Smith I'm going to patent thought. I have yet to see any prior art.

          W Offline
          W Offline
          wow9999
          wrote on last edited by
          #4

          Dear Tim Smith can you show me a example or hint to see a static or non-static funciton to call a static or non-static function. Thanks

          C 1 Reply Last reply
          0
          • W wow9999

            Dear Tim Smith can you show me a example or hint to see a static or non-static funciton to call a static or non-static function. Thanks

            C Offline
            C Offline
            Chris Losinger
            wrote on last edited by
            #5

            class Foo
            {
            public:
            void Blah();

            static void Blech()
            {
            Foo f;
            f.Blah();
            }
            };

            -c


            Image tools: ThumbNailer, Bobber, TIFFAssembler

            1 Reply Last reply
            0
            • W wow9999

              Hi all Can a static function call a non-static function inside the same class? or Can a static function call a non-static function in different class? Thanks

              R Offline
              R Offline
              Ravi Bhavnani
              wrote on last edited by
              #6

              A static method doesn't have a this reference. Hence, it can only call other static methods of its class. However, if the static method has access to an instance of a class, it can call that instance's static or non-static method.

              class Foo {
              ...
              public:
              static void staticFuncA();
              static void staticFuncB();
              void nonStaticFunc();
              }

              void Foo::staticFuncA()
              {
              staticFuncB(); // OK
              nonStaticFunc(); // invalid, since no "this" reference

              Foo f;
              f.nonStaticFunc(); // OK
              }

              /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com

              1 Reply Last reply
              0
              • W wow9999

                Hi all Can a static function call a non-static function inside the same class? or Can a static function call a non-static function in different class? Thanks

                B Offline
                B Offline
                Brigsoft
                wrote on last edited by
                #7

                1)Yes, if I pass to the function object of its class. 2) By a same way. ================================ Useful links

                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