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
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
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; }
Pure virtual function is a description of a C++ implementation. An interface is a description of a COM design architecture.
Kuphryn
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
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