I have template in my .h
file:
template <typename T>
void addToolsAreaItem(){
T* item = new T(_image, this);
doSpecifiedStaff<T>(item);
_tools.addTool(item);
}
and its specialization in .cpp
file:
template <>
void ImageWorkspace::addToolsAreaItem<Preview>(){
_preview = std::make_unique<QGraphicsView>(_splitter);
_imagesLayout.addWidget(_preview.get());
}
Class Prewiew
is empty and is used only for specialize behavior of one case (when preview button is toggled).
But I get compiler error:
imageworkspace.h:45: error: new initializer expression list treated as compound expression [-fpermissive]
T* item = new T(_image, this);
^~~~~~~~~~~~~~~~~~~
imageworkspace.h:45: error: no matching function for call to ‘Preview::Preview(ImageWorkspace*)’
T* item = new T(_image, this);
^~~~~~~~~~~~~~~~~~~
Does compiler see specialization? How to fix it?
Function is called as addToolsAreaItem<Preview>()
from sorces.
–Henri Menke
Image.h header
cpp:
Output: