Abstract Class
-
Hi all, How can i create an abstract class without using virtual keyword in c++. Mahesh
-
Hi all, How can i create an abstract class without using virtual keyword in c++. Mahesh
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
-
Hi all, How can i create an abstract class without using virtual keyword in c++. Mahesh
??? 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.
-
Hi all, How can i create an abstract class without using virtual keyword in c++. Mahesh
Is there a particular reason you don't want to use
virtual
? :confused: - Mike -
Hi all, How can i create an abstract class without using virtual keyword in c++. Mahesh
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 -
Is there a particular reason you don't want to use
virtual
? :confused: - MikeI was thinking the same. John
-
Hi all, How can i create an abstract class without using virtual keyword in c++. Mahesh
Just a thought... did you have the
__declspec(novtable)
extension in mind? If so, keep in mind that thenovtable
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 -
Is there a particular reason you don't want to use
virtual
? :confused: - MikeHi Mike, Thanks.. No particular reason mike. It was an interview question. I just want to confirm whether it is possible. Mahesh
-
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