1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | class Shape; class Circle; class Rectangle; class Shape { virtual bool is_equal(const Shape& s) const { return false; }; }; class Rectangle : public Shape { virtual bool is_equal(const Rectangle& r) const { return true; }; }; int main(void) { Rectangle x; Shape y; return x.is_equal(y); } |
Y2xhc3MgU2hhcGU7CmNsYXNzIENpcmNsZTsKY2xhc3MgUmVjdGFuZ2xlOwoKY2xhc3MgU2hhcGUKewogICAgdmlydHVhbCBib29sIGlzX2VxdWFsKGNvbnN0IFNoYXBlJiBzKSBjb25zdCB7IHJldHVybiBmYWxzZTsgfTsKfTsKCmNsYXNzIFJlY3RhbmdsZSA6IHB1YmxpYyBTaGFwZQp7CiAgICB2aXJ0dWFsIGJvb2wgaXNfZXF1YWwoY29uc3QgUmVjdGFuZ2xlJiByKSBjb25zdCB7IHJldHVybiB0cnVlOyB9Owp9OwoKaW50IG1haW4odm9pZCkKewogICAgUmVjdGFuZ2xlIHg7CiAgICBTaGFwZSB5OwogICAgcmV0dXJuIHguaXNfZXF1YWwoeSk7Cn0K
prog.cpp: In function ‘int main()’: prog.cpp:19: error: no matching function for call to ‘Rectangle::is_equal(Shape&)’ prog.cpp:12: note: candidates are: virtual bool Rectangle::is_equal(const Rectangle&) const
-
result: Compilation error (maybe you wish to see an example for C++ 4.7.2)


