1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | struct Shape; struct Circle; struct Rectangle; struct Shape { virtual bool is_equal(const Shape& s) const { return false; }; }; struct Rectangle : Shape { virtual bool is_equal(const Rectangle& r) const { return true; }; }; int main(void) { Rectangle x; Shape y; return x.is_equal(y); } |
c3RydWN0IFNoYXBlOwpzdHJ1Y3QgQ2lyY2xlOwpzdHJ1Y3QgUmVjdGFuZ2xlOwoKc3RydWN0IFNoYXBlCnsKICAgIHZpcnR1YWwgYm9vbCBpc19lcXVhbChjb25zdCBTaGFwZSYgcykgY29uc3QgeyByZXR1cm4gZmFsc2U7IH07Cn07CgpzdHJ1Y3QgUmVjdGFuZ2xlIDogU2hhcGUKewogICAgdmlydHVhbCBib29sIGlzX2VxdWFsKGNvbnN0IFJlY3RhbmdsZSYgcikgY29uc3QgeyByZXR1cm4gdHJ1ZTsgfTsKfTsKCmludCBtYWluKHZvaWQpCnsKICAgIFJlY3RhbmdsZSB4OwogICAgU2hhcGUgeTsKICAgIHJldHVybiB4LmlzX2VxdWFsKHkpOwp9Cg==
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)


