11 ms·
whats the advantage over declaring register_device as a functor object from an anon class? for example: class Device; class VFS { public: class { f
by mkettn 7y ago
whats the advantage over declaring register_device as a functor object from an anon class?
for example:
class Device;
class VFS {
public:
class {
friend Device;
void operator()(int y) {/* do stuff with y here*/}} register_device;
};
class Device {
public:
void foo(VFS fs) {
fs.register_device(1);
}
};
int main(int argc, char *argv[]) {
// fails:
// VFS().register_device(2);
// works:
Device().foo(VFS());
return 0;
}
and no need for a badge class (erm... well but an anon class).
my c++ skills are a bit rusty, because most of the time python works just fine.
- akling 7y agoHmm, IMO Badge has two main advantages over your approach: 1. Aesthetics. (This is down to personal taste of course, but I much prefer how Badge gets the job done without needing multiple lines of code at every declaration.) 2. What if I need to put the function implementation out-of-line?