Recommended Answers
Jump to PostYou cannot change a function's behaviour on an object, only on a class. To get the exact functionality you showed you would have to use a function pointer as a member of the test class:
class test {// private: public: event<>(*Printed)(); test() { Printed=[]{;}//I have yet to …
Jump to PostThe problem is that you cannot run code in the global scope. The global scope is only for declarations or definitions, not for expressions (executing code). You have to move your setting for the Printed functor in the main function:
#include <iostream> #include <string> #include "events.h" using …
Jump to PostI tested the code (that I posted in my last post, and using your implementation of the "events" class) and it all works, no warnings, no errors, and runs as expected, with the correct output.
…if i'm overloading '()' operator, why i can't use it, outside of main?
Jump to PostI think Labdabeta misunderstood your code. He thought that your declaration of
Printed
was meant to be a function pointer to a function that takes no argument and returns aevents<>
object. In reality, your declaration ofPrinted
was a declaration of a data member of typeevents<>
with an …
All 15 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.