From 294b61072e9e0eb552afa063942a0c7813784138 Mon Sep 17 00:00:00 2001 From: Pagwin Date: Wed, 11 Dec 2024 13:15:25 -0500 Subject: [PATCH] changed track to use default param --- .gitignore | 1 + track.cpp | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 98629db..7aabc6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ i s t +.clangd diff --git a/track.cpp b/track.cpp index 3af2fa3..a2c39de 100644 --- a/track.cpp +++ b/track.cpp @@ -1,5 +1,6 @@ #include #include +// requires C++23 to compile class A { long long counter = 0; @@ -10,7 +11,8 @@ public: ret.counter++; return ret; } - A operator[](int dummy) { + // requires C++23 to compile + A operator[](int _ = 0) { A ret = *this; ret.counter--; return ret; @@ -23,8 +25,8 @@ public: int main(void) { A a; - std::cout << a[0] << std::endl; - std::cout << a[0]() << std::endl; - std::cout << a[0]()() << std::endl; + std::cout << a[] << std::endl; + std::cout << a[]() << std::endl; + std::cout << a[]()() << std::endl; return 0; }