Exact Difference between an Abstract Class and Interface in COM.
-
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
-
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
uday kiran janaswamy wrote:
- 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:
- 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] -
uday kiran janaswamy wrote:
- 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:
- 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]Thanks Cedric Moonen you have given a most valuable information about Abstract Class and an Interface.
Uday kiran
-
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
uday kiran janaswamy wrote:
- 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:
- 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[][^]
-
uday kiran janaswamy wrote:
- 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:
- 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[][^]
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] -
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]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[][^]
-
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
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 helpsIf 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.