There is a function that uses one of two classes of descendants and is called via std::thread(MyFunc, std::ref(SpecifiedClassType)).detach() ;
The parent class does not have some descendant methods; therefore, it is not an option to declare the objects of the descendants as a parent type.
Is it possible to somehow specify which classes can be a variable in this function, or are there no options besides template<class T> ?
Explanation:
There is a class Capture which has two children - Camera and Screen . The purpose of this system is to receive frames from the camera or screenshots of the screen - and nothing more (the network should not be there). The parent has a common for children function GrabJPG , which is called in the external function, in the stream. I want the MyFunc function that I mentioned at the beginning of the topic to look something like this:
void StreamThread(STREAMER &cgf, <только_тип_Camera_или_Screen> &source){ // где cfg - структура с параметрами сетевой конфигурации, // а source - источник кадров - камера или экран. // ... cgf.connection->open(cgf.host, cgf.port) // ... туда-сюда настройки while (cgf.connection->active()){ // ... int size = source->GrabJPG(&buffer); if( size){ cgf.connection->transmit(buffer, size); } // ... } } Now I have two such identical StreamThread , differing only in one variable - the class of the camera or the screen. Not beautiful, agree? There should be a compilation error if you try to thrust into the function any other class that is not a descendant of Capture . This is what is required.
std::threador about where it all comes from? From where and why istemplate<class T>? Give a meaningful context, and not some kind of mess-mess. - AnT