I am writing a library in C++ and have some functions that work with modules. An example would look like this:
void connect(Module *a, Module *b);
The problem is, that it would be sometimes handy if the function accepted also references (some of the Modules may be allocated on the stack and some on the heap and all the &s and *s get boring and messy soon).
Now I have inlined function that takes references, turns them into pointers and calls the original function.
inline void connect(Module &a, Module &b){
connect(&a, &b);
}
I don't like this solution much, because for a few more functions it makes a lot of code to write, read, compile, ...
Another thing that was thinking about is adding Module::operator Module *()
that would hust return this
.
What are your thoughts on this? Isn't there any potential for epic failure that I missed?
Thanks.