c++ - no matching function error in the case of relation between base class and extend class -


i got 2 classes: tjob , reload_job. reload_job extends tjob:

class reload_job: public tjob  

i got function:

void run_all_threads(std::vector<tjob*> &jobs){...} 

and call:

std::vector<reload_job*> jobs; thread_pool->run_all_threads(jobs); //error: no matching function 

a got error @ call. however, if changed function's form into:

void run_all_threads(tjob* job) 

and call:

reload_job* job; thread_pool->run_all_threads(job); work 

could guys me explain why got compling error in case of vector of tjob pointer. much!

your issue stems fact vector< reload_job* > not sub-type of vector< tjob* >, though reload_job sub-type of tjob.

in first example, compiler searches function signature run_all_threads(vector < reload_job* >). there no function signature.

void run_all_threads(std::vector<tjob*> &jobs){...} std::vector<reload_job*> jobs; thread_pool->run_all_threads(jobs); //error: no function matches run_all_threads(vector <reload_job*>) 

however, in second case, reload_job tjob, compiler matches functions.

void run_all_threads(tjob* job) reload_job* job; thread_pool->run_all_threads(job); compiler matches function 

to solve issue, change parameter function vector< tjob* >. can store reload_jobs in vector < tjob* >, since reload_job tjob.

void run_all_threads(std::vector<tjob*> &jobs){...} // function signature doesn't change std::vector<tjob*> jobs; // vector can store tjob and/or reload_job thread_pool->run_all_threads(jobs); // types match 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -