OK, so I'm trying to override the function in a parent class, and I'm getting some errors Here is a test case
#include & lt; Iostream & gt; using namespace std; Class A {public: int aba; Zero Printba (); }; Class B: Public A {Public: Zero Printba (new); }; Zero A :: Print Aba () {cout & lt; & Lt; "ABA1" & lt; & Lt; Endl; } Zero B: PrintAbba () New {cout & lt; & Lt; "ABA 2" & lt; & Lt; Endl; } Int main () {A a = B (); A.printAba (); Return 0; }
And here I am receiving the error:
error 1 error C3662: 'B :: printAba': override specifier 'new' only C: \ users \ test \ test \ test.cpp 12 Exam Error 2 Error C2723: 'B :: printAba': Function Definition 'New' storage-class specifier invalid on member functions: members \ testers \ Test \ test.cpp 19 test
How can I do this? There is no need to enter any keyword in the derived class to override the
function.
Class B: Public A {public: Zero print now (); };
But the method of the base class must be virtual, so that the method can be chosen based on the actual identity of the variable.
class A {public: int aba; Virtual Zodiac print (); };
And if you make a b on the stack and copy it in A you should make b on the stack and put the pointer as A.
A * A = new B (); To do this & gt; PrintAba (); // If printAba is not virtual, A: printAba will be called. Delete;
Comments
Post a Comment