johnsfine |
01-31-2013 05:35 PM |
Quote:
Originally Posted by JohnGraham
(Post 4881200)
Also, your function dealDamage() is taking an instance of Creature
|
It might not be "also". That might be the entire problem.
An object of the class with a pure virtual function cannot exist, which also implies it cannot be passed by value.
As already explained, you can have a reference or a pointer to an object of that class, but at run time that will point to the base class portion of a derived object. It cannot point to a stand alone object.
Quote:
(Note, I'm not actually compiling it, this is just Eclipse telling me I have an error.)
|
It is a misleading error message, but basically correct. There is use of an object in which a virtual function is undefined. The compiler generally can't know which is the bug: Was it a bug to use an object of that class? Or was it a bug to have the function undefined? Whatever code analysis generated that error jumped to the conclusion that having the function undefined was the error. One can never be sure of that error. The error always might be using an object of a type for which only pointers and references can be used. In this case it is far more plausible that use of the object (passing it by value) was wrong, and leaving the function undefined was not wrong. But this unfortunately is not worse than average for error message quality in C++. Distinguishing correct from incorrect is hard enough. Reporting the correct aspect of something incorrect is almost impossible.
|