I want to know if i don’t put override key word before the method in derived class method m1(), then what is the default value before this, or will it throw a compile time error?
class A { virtual void m1(){} }
class B: A { void m1(){} }
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First, you’ll get a compile-time error because
virtualmembers can not be private whichA.m1is as written.Second, once you fix this, you’ll get a compile-time warning that
B.m1hides the inherited memberA.m1.Third, if you do something like this:
This will invoke
A.m1whereas if you insertoverrideinto the definition ofB.m1then the above will invokeB.m1. However, if you insertnewinto the definition ofB.m1then the above will still invokeA.m1but it will omit the compile-time warning.