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. Abstract Class

Abstract Class

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
9 Posts 7 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.
  • M Offline
    M Offline
    Mahesh Varma
    wrote on last edited by
    #1

    Hi all, How can i create an abstract class without using virtual keyword in c++. Mahesh

    R J Z N 5 Replies Last reply
    0
    • M Mahesh Varma

      Hi all, How can i create an abstract class without using virtual keyword in c++. Mahesh

      R Offline
      R Offline
      realJSOP
      wrote on last edited by
      #2

      You can't. ------- signature starts "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 "You won't like me when I'm angry..." - Dr. Bruce Banner Please review the Legal Disclaimer in my bio. ------- signature ends

      1 Reply Last reply
      0
      • M Mahesh Varma

        Hi all, How can i create an abstract class without using virtual keyword in c++. Mahesh

        J Offline
        J Offline
        Jonathan de Halleux
        wrote on last edited by
        #3

        ??? If you use inherance overloading without virtual you will run into trouble. If you want to avoid virtual methods, use template meta programming. Jonathan de Halleux.

        1 Reply Last reply
        0
        • M Mahesh Varma

          Hi all, How can i create an abstract class without using virtual keyword in c++. Mahesh

          Z Offline
          Z Offline
          ZoogieZork
          wrote on last edited by
          #4

          Is there a particular reason you don't want to use virtual? :confused: - Mike

          J M 2 Replies Last reply
          0
          • M Mahesh Varma

            Hi all, How can i create an abstract class without using virtual keyword in c++. Mahesh

            N Offline
            N Offline
            Navin
            wrote on last edited by
            #5

            You can't - an abstract class is defined as having at least one method be virtual and not having an implementation. e.g.,class VirtualClass { public: virtual void OverrideMe() = 0; };
            A compiler won't let you instantiate such a class. If you can instantiate it, then it is not an abstract class. "When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity." - Albert Einstein

            M 1 Reply Last reply
            0
            • Z ZoogieZork

              Is there a particular reason you don't want to use virtual? :confused: - Mike

              J Offline
              J Offline
              John M Drescher
              wrote on last edited by
              #6

              I was thinking the same. John

              1 Reply Last reply
              0
              • M Mahesh Varma

                Hi all, How can i create an abstract class without using virtual keyword in c++. Mahesh

                Z Offline
                Z Offline
                ZoogieZork
                wrote on last edited by
                #7

                Just a thought... did you have the __declspec(novtable) extension in mind? If so, keep in mind that the novtable attribute does not semantically mark the class as abstract; rather, it just removes the vtable initialization code. It just happens that this is most useful for application to abstract classes. - Mike

                1 Reply Last reply
                0
                • Z ZoogieZork

                  Is there a particular reason you don't want to use virtual? :confused: - Mike

                  M Offline
                  M Offline
                  Mahesh Varma
                  wrote on last edited by
                  #8

                  Hi Mike, Thanks.. No particular reason mike. It was an interview question. I just want to confirm whether it is possible. Mahesh

                  1 Reply Last reply
                  0
                  • N Navin

                    You can't - an abstract class is defined as having at least one method be virtual and not having an implementation. e.g.,class VirtualClass { public: virtual void OverrideMe() = 0; };
                    A compiler won't let you instantiate such a class. If you can instantiate it, then it is not an abstract class. "When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity." - Albert Einstein

                    M Offline
                    M Offline
                    melwyn
                    wrote on last edited by
                    #9

                    We can prevent the instantiation of the class by making it's constructors private, however the problem with this is that the class cannot be derived then.

                    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