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. Pure virtual function in other compilers

Pure virtual function in other compilers

Scheduled Pinned Locked Moved C / C++ / MFC
c++
7 Posts 5 Posters 1 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
    vibindia
    wrote on last edited by
    #1

    Hi class A { public: virtual void fun()=0 { cout<<"hai";//code inside in an pure virtual function } }; this works in VC++.(code inside an pure virtual function) Is the same thing work in other compilers of C++:confused:

    VIBIN "Fool's run away,where angle's fear to tread"

    C V C D J 5 Replies Last reply
    0
    • V vibindia

      Hi class A { public: virtual void fun()=0 { cout<<"hai";//code inside in an pure virtual function } }; this works in VC++.(code inside an pure virtual function) Is the same thing work in other compilers of C++:confused:

      VIBIN "Fool's run away,where angle's fear to tread"

      C Offline
      C Offline
      C Mahesh
      wrote on last edited by
      #2

      I have the following questions : 1.Which version of VC++ compiler did you use? 2.What is your understanding of pure virtual functions?

      1 Reply Last reply
      0
      • V vibindia

        Hi class A { public: virtual void fun()=0 { cout<<"hai";//code inside in an pure virtual function } }; this works in VC++.(code inside an pure virtual function) Is the same thing work in other compilers of C++:confused:

        VIBIN "Fool's run away,where angle's fear to tread"

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

        the version is VC++6.0 My understanding of Virtual fuction It creates an V table, which provides run time ploymorphism, And an pure virtual function makes the calss an Abstract base class.

        VIBIN "Fool's run away,where angle's fear to tread"

        C 1 Reply Last reply
        0
        • V vibindia

          the version is VC++6.0 My understanding of Virtual fuction It creates an V table, which provides run time ploymorphism, And an pure virtual function makes the calss an Abstract base class.

          VIBIN "Fool's run away,where angle's fear to tread"

          C Offline
          C Offline
          C Mahesh
          wrote on last edited by
          #4

          Great, As for i am aware, the compiler should not allow it, and even if it allows what is the use of it when the class is abstract. P.S: I have checked with VC++7.0, it gives an error

          1 Reply Last reply
          0
          • V vibindia

            Hi class A { public: virtual void fun()=0 { cout<<"hai";//code inside in an pure virtual function } }; this works in VC++.(code inside an pure virtual function) Is the same thing work in other compilers of C++:confused:

            VIBIN "Fool's run away,where angle's fear to tread"

            C Offline
            C Offline
            Cedric Moonen
            wrote on last edited by
            #5

            The error will only be displayed if you try to actually instantiate the class: A myInstance; // This will fail But VC6 is also a very old compiler and not fully compliant to the actual standard.


            Cédric Moonen Software developer
            Charting control [v1.2]

            1 Reply Last reply
            0
            • V vibindia

              Hi class A { public: virtual void fun()=0 { cout<<"hai";//code inside in an pure virtual function } }; this works in VC++.(code inside an pure virtual function) Is the same thing work in other compilers of C++:confused:

              VIBIN "Fool's run away,where angle's fear to tread"

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              vibindia wrote:

              Is the same thing work in other compilers of C++

              That sounds like a try-it-and-see question.


              "A good athlete is the result of a good and worthy opponent." - David Crow

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              1 Reply Last reply
              0
              • V vibindia

                Hi class A { public: virtual void fun()=0 { cout<<"hai";//code inside in an pure virtual function } }; this works in VC++.(code inside an pure virtual function) Is the same thing work in other compilers of C++:confused:

                VIBIN "Fool's run away,where angle's fear to tread"

                J Offline
                J Offline
                James R Twine
                wrote on last edited by
                #7

                I believe that it is completely valid.  Declaring a function as pure virtual does not mean that does not have an implementation, only that you have to provide one in a derived class.    This can (and has) been used to force developers to customize behavior for their derived classes, but still provide an implementation in the base class.    It should only give you an error if you try to directly instantiate an instance of that base class, or of a derived on that does not provide an implementation for the PV function.    Of course, I could be wrong here...    Peace!

                -=- James
                Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                See DeleteFXPFiles

                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