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. Exact Difference between an Abstract Class and Interface in COM.

Exact Difference between an Abstract Class and Interface in COM.

Scheduled Pinned Locked Moved C / C++ / MFC
comquestion
7 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.
  • U Offline
    U Offline
    uday kiran janaswamy
    wrote on last edited by
    #1

    Hi all, I Want to Know About 1) Why can't we directly instantiate an Abstract Class, and why we have to create it by its Derived Class only. 2) What is the Difference between an Abstract Class and an Interface in COM. Please give your suggestions.

    Uday kiran

    C P CPalliniC 3 Replies Last reply
    0
    • U uday kiran janaswamy

      Hi all, I Want to Know About 1) Why can't we directly instantiate an Abstract Class, and why we have to create it by its Derived Class only. 2) What is the Difference between an Abstract Class and an Interface in COM. Please give your suggestions.

      Uday kiran

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

      uday kiran janaswamy wrote:

      1. Why can't we directly instantiate an Abstract Class, and why we have to create it by its Derived Class only.

      Because that's one of the C++ feature (and it is a very valuable feature: it prevents user to instantiate classes that are not supposed to be instancied). By supplying at least one pure virtual function, your class is abstract:

      CMyClass
      {
      virtual void MyFunc() = 0; // Pure virtual function
      };

      uday kiran janaswamy wrote:

      1. What is the Difference between an Abstract Class and an Interface in COM.

      For me (but I don't know if this is totally true), an abstract class is a class that cannot be instantiated directly (meaning it has at least one pure virtual function). A interface is a "pure abstract class": a class that has only member functions (no member variables) and all of them are pure virtual. In fact this class has no functionality at all, it is just an interface to a class that implements those functionalities.


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

      U 1 Reply Last reply
      0
      • C Cedric Moonen

        uday kiran janaswamy wrote:

        1. Why can't we directly instantiate an Abstract Class, and why we have to create it by its Derived Class only.

        Because that's one of the C++ feature (and it is a very valuable feature: it prevents user to instantiate classes that are not supposed to be instancied). By supplying at least one pure virtual function, your class is abstract:

        CMyClass
        {
        virtual void MyFunc() = 0; // Pure virtual function
        };

        uday kiran janaswamy wrote:

        1. What is the Difference between an Abstract Class and an Interface in COM.

        For me (but I don't know if this is totally true), an abstract class is a class that cannot be instantiated directly (meaning it has at least one pure virtual function). A interface is a "pure abstract class": a class that has only member functions (no member variables) and all of them are pure virtual. In fact this class has no functionality at all, it is just an interface to a class that implements those functionalities.


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

        U Offline
        U Offline
        uday kiran janaswamy
        wrote on last edited by
        #3

        Thanks Cedric Moonen you have given a most valuable information about Abstract Class and an Interface.

        Uday kiran

        1 Reply Last reply
        0
        • U uday kiran janaswamy

          Hi all, I Want to Know About 1) Why can't we directly instantiate an Abstract Class, and why we have to create it by its Derived Class only. 2) What is the Difference between an Abstract Class and an Interface in COM. Please give your suggestions.

          Uday kiran

          P Offline
          P Offline
          prasad_som
          wrote on last edited by
          #4

          uday kiran janaswamy wrote:

          1. Why can't we directly instantiate an Abstract Class, and why we have to create it by its Derived Class only.

          Because, its not complete on its own.

          uday kiran janaswamy wrote:

          1. What is the Difference between an Abstract Class and an Interface in COM.

          To add to Cedric, abstract class can have some functions with definitions. But that could not be case with interface, It will have only pure virtual fucntions. To stick to this, later VS compiler provide keyword __interface.

          Prasad Notifier using ATL | Operator new[],delete[][^]

          C 1 Reply Last reply
          0
          • P prasad_som

            uday kiran janaswamy wrote:

            1. Why can't we directly instantiate an Abstract Class, and why we have to create it by its Derived Class only.

            Because, its not complete on its own.

            uday kiran janaswamy wrote:

            1. What is the Difference between an Abstract Class and an Interface in COM.

            To add to Cedric, abstract class can have some functions with definitions. But that could not be case with interface, It will have only pure virtual fucntions. To stick to this, later VS compiler provide keyword __interface.

            Prasad Notifier using ATL | Operator new[],delete[][^]

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

            prasad_som wrote:

            To add to Cedric, abstract class can have some functions with definitions.

            Well, it was implicitely stated: the only restriction of an abstract class is that it cannot be instanciated (so at least one pure virtual function). Now, you can have whatever you want in the class (even member variables).


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

            P 1 Reply Last reply
            0
            • C Cedric Moonen

              prasad_som wrote:

              To add to Cedric, abstract class can have some functions with definitions.

              Well, it was implicitely stated: the only restriction of an abstract class is that it cannot be instanciated (so at least one pure virtual function). Now, you can have whatever you want in the class (even member variables).


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

              P Offline
              P Offline
              prasad_som
              wrote on last edited by
              #6

              Cedric Moonen wrote:

              Well, it was implicitely stated

              I mentioned this to differentiate it from interface. And should be.

              Prasad Notifier using ATL | Operator new[],delete[][^]

              1 Reply Last reply
              0
              • U uday kiran janaswamy

                Hi all, I Want to Know About 1) Why can't we directly instantiate an Abstract Class, and why we have to create it by its Derived Class only. 2) What is the Difference between an Abstract Class and an Interface in COM. Please give your suggestions.

                Uday kiran

                CPalliniC Offline
                CPalliniC Offline
                CPallini
                wrote on last edited by
                #7

                uday kiran janaswamy wrote:

                What is the Difference between an Abstract Class and an Interface in COM.

                a COM interface has more constraints (or features) than an C++ abstract class, i.e. a COM interface is an abstract class: (1) having only methods. (2) having a unique global identifier. (3) exposing, at least, the methods of the IUnknown interface (QueryInterface, AddRef, Release). hope that helps

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                In testa che avete, signor di Ceprano?

                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