Skip to content

Instantly share code, notes, and snippets.

@haxscramper
Created June 25, 2018 17:11
Show Gist options
  • Save haxscramper/7a1c285e2be6fea79408da7a7b5c2e39 to your computer and use it in GitHub Desktop.
Save haxscramper/7a1c285e2be6fea79408da7a7b5c2e39 to your computer and use it in GitHub Desktop.
C++ operator overloading.
#include <string>
#include <iostream>
struct Test {
std::string word;
Test& operator()() { return *this; }
std::string operator()(float f) { return word; }
Test& operator[](std::string w) {
word.append(w);
return *this;
}
};
int main() {
Test test;
std::cout << test()["3"]()["34"]()["34534"]()["23"](3.4) << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment