Relative Content

Tag Archive for functions

Is a callback function with `this` as an argument a bad practice?

I have a class that has a callback function that gets triggered on some event. The user of the class instance is expected to do stuff on the instance itself, inside this callback function. So I am wondering if I should add the instance itself as an argument to the callback.

Why do you need to use pass by reference in C++ to change the value of the arguments inside the function?

I’m new to coding and am currently trying to learn C++ myself. I just learned about function parameters and pass by value vs pass by reference. Everywhere I read, they say that one of the reasons pass by reference is useful is because it allows you to change the value of an argument inside the function. But why does making the parameter variable a reference let you do that? And why can’t you do that if you pass a value instead?