c++ - 2D Array of objects with virtual child methods -> "vtable referenced from" error -


in header tile class, defined pure virtual method no definition in implementation: virtual void setvals(int id) = 0;

the 2 classes inherit tile (terrain , actor) both overwrite setvals method implementations:

void terrain::setvals(int id){     switch(id){         case 1 : gfx_ = '.'; name_ = "grass"; desc_ = "some grass"; break;         default: gfx_ = '?'; name_ = "error"; desc_ = "error"; tile::ispassable_ = false; break;     } } 

and

void tile::setvals(int id){     switch(id){         case 1 : gfx_ = '?'; name_ = "nothing"; desc_ = "you shouldn't seeing this"; break;         case 0 : gfx_ = '@'; name_ = "player"; desc_ = "the player"; break;         default: gfx_ = '?'; name_ = "error"; desc_ = "error"; tile::ispassable_ = false; break;     } } 

respectively. 2d array of each of these child classes initialized in map class:

terrain terrain_[height][width]; actor actors_[height][width]; 

(where height , width constant ints). when program runs, program returns runtime error reading "'vtable actor', referenced from:". making mistake in how i'm initializing these methods or objects?

you said base class tile, , has following pure virtual method

virtual void setvals(int id) = 0; 

but yet went on define it?

void tile::setvals(int id){     switch(id){         case 1 : gfx_ = '?'; name_ = "nothing"; desc_ = "you shouldn't seeing this"; break;         case 0 : gfx_ = '@'; name_ = "player"; desc_ = "the player"; break;         default: gfx_ = '?'; name_ = "error"; desc_ = "error"; tile::ispassable_ = false; break;     } } 

you need implement actor::setvals if derived class tile


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -