'Duplicate a class method to allow more than one names
Say I have a class like
struct Demo {
void read() { /* some implementation */ }
};
Is it possible to define a method get() that is identical to read() without having to re-write the code?
Obviously the usual shortcut would suffice:
void get() { return read(); }
but I was wondering whether there's a more succinct way, e.g.
struct Demo {
void read() { /* some implementation */ }
void get() = read();
};
I know this is commonplace with operator[] and getX, getY or getX vs x etc in vector-like classes but haven't seen any alternative techniques there. In cases were templates and variadic arguments are involved, it becomes cumbersome to forward all arguments just to create an alias essentially.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
