There is a snippet from my code:
const std::pair<Info, const ElementHandler&>& handle () const {
FileHandler fileHandler = FileHandler();
std::pair<Info, const ElementHandler&> result = std::pair<Info, const FileHandler&> ( info, fileHandler );
return result;
}
I have the following compilation error:
error: cannot declare field ‘std::pair<Synchronizer::Info, Synchronizer::ElementHandler>::second’ to be of abstract type ‘Synchronizer::ElementHandler’
How I can write the code to preserve the idea? Is it possible, or I need use pointers and dynamic allocation?
If that’s the driving need behind your broken code, then I won’t follow the trend by telling you how to fix it to do what you don’t want ;-). Instead, you have to consider the implications properly. You must have some variable with a scope that matches the caller’s needs. Local automatic variables must be ruled out – they are destroyed when the function returns. So, you could:
staticvariable, or a global variable, but that will be the same variable each time the function is called and there could be thread-safety issues (your compiler may support some thread-specific keyword, and POSIX has functions to support thread-specific data – but 1-object-per-thread may still be too limiting)bool load_my_x(X&);)