mardi 10 novembre 2020

C++ Lambda to Function Pointer

I have three classes:

class ShapeEditor {}
class PointEditor: ShapeEditor{}
class RectEditor: ShapeEditor{}

I want to define function pointer in Manager class and pass it in constructor as lambda function. It looks like this:

class Manager {
public:
  ShapeEditor (*factory)();
  Manager(ShapeEditor (*_factory)());
}

Then I'm writing in main:

Manager m = Manager([] { return PointEditor(); }

and getting an error message that there is no constructor for this expression. When I changes ShapeEditor to PointEditor in Manager - it works fine, but I need to specify different types in function result.

Aucun commentaire:

Enregistrer un commentaire