Please help me I am not really good at polarity, I have classes inherited from other classes.
EDIT: Sorry, completely my mistake Even I have spent about 2 hours to find the problem. People who are interested (thanks for all help)
if (type.compare ("TEST1") == 0) Results = New Test (id, database); If (type.compare ("TEST2") == 0) Results = New Test (ID, Database); If (type.compare ("TOR") == 0) results = new tow (id, database); "== 0" was completely unavailable.
class A {public: go to zero (do);} virtual zero () {printf ('a');}} class b: public A {virtual zeros ( (Printf ('B');}} int main {A * obj = new B (); obj- & gt; Go ();} Result 'A' No '
After that I make it 'b' How can I manage? I covered some things to compile it:
#include & lt; stdio.h & gt; class A {public: virtual zero DO) { Printf ("a");} zero go () {DO ();}}; Class B: Public A {virtual zero DO () {printf ("B");}}}; int main () {A * obj = new B (); obj-> Go (); Return 0;} < / Code> ( do is a keyword; printf does not require char, main brackets, And gives an integer) This has ever produced B for me regardless of the optimization level: $ G + + heirs CPP-O beer end & amp; ./inherit b $ g ++ inherit.cpp -O1 -o war & amp; ./inherit b $ g ++ inherit.cpp -O2 -o war & amp; ./ Inherit B $ G ++ Beerius CPP-O3-O Bear End End; ./inherit b $ g ++ inherit.cpp -O4 -o war & amp; ./inherit b $ g ++ inherit.cpp -O5 -o war & amp; However, it is possible that you have filed a case of edge in your compiler, which has to go to do () inside () .
No comments:
Post a Comment