Interview Questions Answers.ORG
Interviewer And Interviewee Guide
Interviews
Quizzes
Home
Quizzes
Interviews C Plus Plus Language Interviews:C++ Access ControlC++ COM ActiveXC++ ConstructorsC++ ContainersC++ Exception HandlingC++ FriendC++ InheritanceC++ Inline FunctionC++ New And DeleteC++ Operator OverloadingC++ Pointers & FunctionsC++ ProgrammerC++ ReferencesC++ Static DataC++ SyntaxC++ TemplateC++ Type CheckingC++ Virtual Functions
Copyright © 2018. All Rights Reserved
C++ Virtual Functions Interview Question:
Tell me can a pure virtual function have an implementation?
Submitted by: MuhammadThe quick answer to that question is yes! A pure virtual function can have an implementation in C++ - which is something that even many veteran C++ developers do not know. So, using the SomeClass class from our example above, we can have the following code:
class SomeClass {
public:
virtual void pure_virtual() = 0; // a pure virtual function
// note that there is no function body
};
/*This is an implementation of the pure_virtual function
which is declared as a pure virtual function.
This is perfectly legal:
*/
void SomeClass::pure_virtual() {
cout <<"This is a test"<< endl;
}< /endl;
Submitted by: Muhammad
class SomeClass {
public:
virtual void pure_virtual() = 0; // a pure virtual function
// note that there is no function body
};
/*This is an implementation of the pure_virtual function
which is declared as a pure virtual function.
This is perfectly legal:
*/
void SomeClass::pure_virtual() {
cout <<"This is a test"<< endl;
}< /endl;
Submitted by: Muhammad
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.
https://InterviewQuestionsAnswers.ORG.