CJCoding With Joseph
15free / daySign inCreate account

Seneca BTP 305

Debugging Function Objects, Lambdas, and Callbacks

Debugging Examples

The following code contains a total of 3 errors. Find and fix them, then post in the community explaining what you found and how you fixed it.


Processor.h

#ifndef PROCESSOR_H
#define PROCESSOR_H
#include <iostream>
#include <functional>

class IntProcessor {
    int value;
public:
    IntProcessor(int v = 0)
        : value(v) {
    }
    struct Multiplier {
        int factor;

        Multiplier(int f = 1)
            : factor(f) {
        }

        int operator()(int x) const {
            return x * factor;
        }
    };

    int applyFunctor(const Multiplier& fun) const {
        return value;
    }

    int applyCallback(int (*callback)(int)) const {
        return callback;
    }

    int applyLambda(const std::function<int(int)>& func) const {
        return func();
    }
};
#endif
Members only

Keep reading this lesson

You've reached the end of the free preview. Unlock the rest of this lesson plus 17 more lessons in Seneca BTP 305.

  • Unlimited coding questions
  • Unlimited access to all classroom material
  • Weekly live call for questions and guidance
  • 3,000 AI tutor tokens / month
  • Personal SQL database (3 MB)
  • Progress tracking

Cancel any time.