difference between pure virtual class and interface

This is a discussion on difference between pure virtual class and interface within the C++ Programming forums, part of the General Programming Boards category; hi guys, what is difference between pure virtual class and interface (with respect to C++ not java).if there is no ...

  1. #1
    kmirza
    Guest

    difference between pure virtual class and interface

    hi guys,
    what is difference between pure virtual class and interface (with respect to C++ not java).if there is no difference then why is there IUKnown interace ?

    kmirza

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    An interface is just a contract in the sense that it is guaranteed to be implemented, ie: there will be a spot on the v-table for that member function. A pure virtual class basically the same thing. All Windows Com objects must implement the IUnknown interface.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Pure virtual function is a description of a C++ implementation. An interface is a description of a COM design architecture.

    Kuphryn

  4. #4
    kmirza
    Guest

    difference between interface and base virtual class

    hi guys,
    the difference i understand from your point of view is that base virtual class has nothing to do with vtable unlike interface.
    anyone to comment on that is welcomed.

    kmirza

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Wrong.

    In C++, there is no concept of the interface. In C++, you have base classes with virtual functions. These virtual functions have entries in the virtual function table, so that polymorphic calls are possible.

    The Component-Object-Model (COM) and its relatives (CORBA, XPCOM, ...) as well as Java define the notion of an interface. An interface is a set of functions that an object promises to support. Interfaces are an abstract concept, the implementation is up to the system.

    In COM and XPCOM the binary representation of an interface "happens" to be the same as of a C++ class that has only pure virtual methods. But any other language with a compiler that can create this binary pattern can create interfaces too (Borland Delphi can do it I think).
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 06-18-2009, 04:58 AM
  2. Platform game gravity problem
    By Akkernight in forum Game Programming
    Replies: 33
    Last Post: 02-22-2009, 12:10 PM
  3. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  4. abstract class
    By xddxogm3 in forum C++ Programming
    Replies: 5
    Last Post: 01-01-2005, 08:08 AM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 01:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21