From ef4538478075dada9161c1f0175ae7409f977603 Mon Sep 17 00:00:00 2001 From: Miguel Date: Thu, 9 Jan 2025 12:39:13 +0100 Subject: building on win --- test.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 test.cpp (limited to 'test.cpp') diff --git a/test.cpp b/test.cpp new file mode 100644 index 0000000..b987af9 --- /dev/null +++ b/test.cpp @@ -0,0 +1,81 @@ +// Some stupid experiments as I forgot C++ + +#include +#include +#include +#include +#include + +class C1 { + +public: + + C1() : name{"default"} { + std::cout << "C1 default cons: " << name << std::endl; + } + + C1(const std::string& str) : name{str} { + std::cout << "C1 cons: " << name << std::endl; + } + + C1(std::initializer_list list) { + for (std::string val : list) name+=val; + std::cout << "C1 initializer_list cons: " << name << std::endl; + } + + ~C1() { + std::cout << "C1 decons: " << name << std::endl; + } + + C1(C1&& other) : name{other.name} { + std::cout << "C1 move constructor: " << name << std::endl; + other.name+=" (moved away)"; + } + + C1& operator=(C1&& other) { + std::cout << "C1 move called: " << other.name << " -> " << name << std::endl; + name = other.name; + other.name+=" (moved away)"; + return *this; + } + + // Disable copy and copy-assign + C1(const C1&) = delete; + C1& operator=(const C1&) = delete; + + void rename (const std::string &str){ + name = str; + } + + void say() { + std::cout << "C1 says: " << name << std::endl; + } + +private: + + std::string name; + +}; + + +int main() { + + std::cout << "Miguel's C++ Tests" << std::endl; + + C1 a ("x"); + C1 b (std::move(a)); + + std::cout << "--" << std::endl; + a.say(); + b.say(); + a.rename("y"); + a.say(); + b.say(); + std::cout << "--" << std::endl; + + C1 c{"c","d"}; + c.say(); + + return EXIT_SUCCESS; + +} -- cgit v1.2.3