mardi 28 janvier 2020

define function template alias by using

I define a function template alias:

template <typename T>
using Cb = typename std::add_pointer<void(bool, T)>::type;

but got this error :

error: cannot convert 'Log::operator()(Read&) [with T = int]::' to 'Cb' {aka 'void (*)(bool, int)'} in assignment

template <typename T>
class Log : public Sink<T> {
public:
    void
    operator()(Read<T> &read) {
        if (!more_) {
            // error !!!
            more_ = std::function<Cb<T>>([&](bool done, T val) {
                if (!done) {
                    cout << val << endl;
                    this->operator()(read);
                }
            });
        }
        read(false, more_);
    }

private:
    Cb<T> more_ = nullptr;
};

main function:

int main() {

    Log<int> logInt;

    return 0;
}

who to resolve this syntax error?

code example

Aucun commentaire:

Enregistrer un commentaire