diff --git a/20230420/ad-20230420.txt b/20230420/ad-20230420.txt new file mode 100644 index 0000000000000000000000000000000000000000..13fb67befa21ab91af18610fd7d4bc12de8ca3e8 --- /dev/null +++ b/20230420/ad-20230420.txt @@ -0,0 +1,31 @@ +Stundenplan-Algorithmus, 20.04.2023, 17:27:42 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Zum Algorithmus von FET: https://lalescu.ro/liviu/fet/doc/en/generation-algorithm-description.html + +gegeben: Input + - Liste der Lehrveranstaltungen + - Liste der Studierendengruppen mit zeitlichen Einschränkungen + - Liste der Lehrenden mit zeitlichen Einschränkungen + +für jede Lehrveranstaltung: + Schritt 1: Nächstbesten freien Platz im Stundenplan wählen + Vorbedingungen: einige Lehrveranstaltungen wurden bereits plaziert + Dafür benötigt: + - Funktion, die auf Konflikte prüft: Bitmasken verwenden? + - Funktion, die den nächsten freien Slot findet + Schritt 2: Falls es keinen freien Platz gibt: + - irgendwas anderes wegschieben + - Was??? Wohin??? + +--> Neue Idee + + Falls es keinen freien Platz gibt: + Reihenfolge der "freifliegenden" Lehrveranstaltungen ändern + von vorne beginnen + +Stundenplan als Bitmaske: + 4 * 11 + 1 = 45 Viertelstunden pro Tag an 5 Tagen pro Woche + = (4 * 11 + 1) * 5 = 225 Bit + +Bitmasken für Module berechnen. +Mit dem Modul beginnen, das die wenigsten Möglichkeiten hat. diff --git a/20230427/exceptions-0.cpp b/20230427/exceptions-0.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6319e0e69bc10a3cd80e72d1663357fcdadde071 --- /dev/null +++ b/20230427/exceptions-0.cpp @@ -0,0 +1,19 @@ +#include <iostream> + +using namespace std; + +int main () +{ + int a = 42; + int b = 0; + if (b == 0) + { + cout << "Irgendwas ist schiefgelaufen: Ganzzahldivision durch Null" << endl; + } + else + { + int c = a / b; + cout << "c = " << c << endl; + } + return 0; +} diff --git a/20230427/exceptions-1.cpp b/20230427/exceptions-1.cpp new file mode 100644 index 0000000000000000000000000000000000000000..72db25aeeb34cf37d07a6f78eea2d55bf0db2851 --- /dev/null +++ b/20230427/exceptions-1.cpp @@ -0,0 +1,21 @@ +#include <iostream> + +using namespace std; + +int main () +{ + try + { + int a = 42; + int b = 0; + if (b == 0) + throw "Ganzzahldivision durch Null"; + int c = a / b; + cout << "c = " << c << endl; + } + catch (const char *msg) + { + cout << "Irgendwas ist schiefgelaufen: " << msg << endl; + } + return 0; +} diff --git a/20230427/exceptions-10.cpp b/20230427/exceptions-10.cpp new file mode 100644 index 0000000000000000000000000000000000000000..35ddd03d74208975a496b879372a28ebda9af7a3 --- /dev/null +++ b/20230427/exceptions-10.cpp @@ -0,0 +1,42 @@ +#include <iostream> +#include <sstream> + +using namespace std; + +class philosophy_exception: public exception +{ + int answer; + static const char *buffer; +public: + philosophy_exception (int a) { answer = a; } + virtual const char *what () const noexcept; +}; + +const char *philosophy_exception::what () const noexcept +{ + return buffer; +// ostringstream buffer; +// buffer << "philosophy exception #" << answer; +// return buffer.str ().c_str (); +} + +const char *philosophy_exception::buffer = "Marvin"; + +int main () +{ + int answer; + cout << "What's your answer? "; + cin >> answer; + try + { + if (answer == 42) + cout << "And what was the question?" << endl; + else + throw philosophy_exception (answer); + } + catch (exception &e) + { + cout << "caught exception: " << e.what () << endl; + } + return 0; +} diff --git a/20230427/exceptions-11.cpp b/20230427/exceptions-11.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6188c398a67c45d754ec0a014b7f93caebc2ce75 --- /dev/null +++ b/20230427/exceptions-11.cpp @@ -0,0 +1,43 @@ +#include <iostream> +#include <sstream> +#include <string.h> + +using namespace std; + +class philosophy_exception: public exception +{ + int answer; + static char buffer[42]; +public: + philosophy_exception (int a) { answer = a; } + virtual const char *what () const noexcept; +}; + +const char *philosophy_exception::what () const noexcept +{ + ostringstream tmp_buffer; + tmp_buffer << "philosophy exception #" << answer; + strcpy (buffer, tmp_buffer.str ().c_str ()); + return buffer; +} + +char philosophy_exception::buffer[42] = "Marvin"; + +int main () +{ + int answer; + cout << "What's your answer? "; + cin >> answer; + try + { + if (answer == 42) + cout << "And what was the question?" << endl; + else + throw philosophy_exception (answer); + } + catch (exception &e) + { + cout << "caught exception: " << e.what () << endl; + } + return 0; +} diff --git a/20230427/exceptions-1a.cpp b/20230427/exceptions-1a.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3666f51fc4f22ef3dfd1c1747cfc6bb78ef8e640 --- /dev/null +++ b/20230427/exceptions-1a.cpp @@ -0,0 +1,17 @@ +#include <iostream> + +using namespace std; + +int main () +{ + int a = 42; + int b = 0; + if (b == 0) + { + cout << "Irgendwas ist schiefgelaufen: " << "Ganzzahldivision durch Null" << endl; + return 1; + } + int c = a / b; + cout << "c = " << c << endl; + return 0; +} diff --git a/20230427/exceptions-1b.cpp b/20230427/exceptions-1b.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d47f27d79691d7f30823bc31075d56fee7ac72c5 --- /dev/null +++ b/20230427/exceptions-1b.cpp @@ -0,0 +1,21 @@ +#include <iostream> + +using namespace std; + +int main () +{ + try + { + int a = 42; + int b = 0; + if (b == 0) + throw "Ganzzahldivision durch Null"; + int c = a / b; + cout << "c = " << c << endl; + } + catch (int msg) + { + cout << "Irgendwas ist schiefgelaufen: " << msg << endl; + } + return 0; +} diff --git a/20230427/exceptions-1c.cpp b/20230427/exceptions-1c.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3322800f50b2b5687a559dcb0d8dc93e0a3f7c49 --- /dev/null +++ b/20230427/exceptions-1c.cpp @@ -0,0 +1,19 @@ +#include <iostream> + +using namespace std; + +int main () +{ + try + { + int a = 42; + int b = 0; + int c = a / b; + cout << "c = " << c << endl; + } + catch (int msg) + { + cout << "Irgendwas ist schiefgelaufen: " << msg << endl; + } + return 0; +} diff --git a/20230427/exceptions-2.cpp b/20230427/exceptions-2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fd78e31adaa1b477a0dc6063f25b2fc96b23420e --- /dev/null +++ b/20230427/exceptions-2.cpp @@ -0,0 +1,43 @@ +#include <iostream> + +using namespace std; + +void check_answer (int answer) +{ + if (answer != 42) + { + try + { + if (answer == 10) + throw answer; + else if (answer == 137) + throw "alpha"; + } + catch (int e) + { + cout << "Yeah!" << endl; + throw; + } + throw "bullshit"; + } +} + +int main () +{ + int answer; + cout << "What's your answer? "; + cin >> answer; + try + { + if (answer == 23) + throw answer; + else + check_answer (answer); + } + catch (const char *e) + { + cout << "caught string exception: " << e << endl; + } + cout << "And what was the question?" << endl; + return 0; +} diff --git a/20230427/exceptions-2a.cpp b/20230427/exceptions-2a.cpp new file mode 100644 index 0000000000000000000000000000000000000000..584107aa74d22aeb72d3455f5cfd4625c181ac76 --- /dev/null +++ b/20230427/exceptions-2a.cpp @@ -0,0 +1,42 @@ +#include <iostream> + +using namespace std; + +void check_answer (int answer) +{ + if (answer != 42) + { + try + { + if (answer == 10) + throw answer; + if (answer == 137) + throw "alpha"; + } + catch (int e) + { + cout << "Yeah!" << endl; + throw; + } + throw "bullshit"; + } +} + +int main () +{ + int answer; + cout << "What's your answer? "; + cin >> answer; + try + { + if (answer == 23) + throw answer; + check_answer (answer); + } + catch (const char *e) + { + cout << "caught string exception: " << e << endl; + } + cout << "And what was the question?" << endl; + return 0; +} diff --git a/20230427/exceptions-2b.cpp b/20230427/exceptions-2b.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7872f5738800eb09c386ed87811db26c43260fb1 --- /dev/null +++ b/20230427/exceptions-2b.cpp @@ -0,0 +1,46 @@ +#include <iostream> + +using namespace std; + +void check_answer (int answer) +{ + if (answer != 42) + { + try + { + if (answer == 10) + throw answer; + if (answer == 137) + throw "alpha"; + } + catch (int e) + { + cout << "Yeah!" << endl; + throw; + } + throw "bullshit"; + } +} + +int main () +{ + int answer; + cout << "What's your answer? "; + cin >> answer; + try + { + if (answer == 23) + throw answer; + check_answer (answer); + } + catch (const char *e) + { + cout << "caught string exception: " << e << endl; + } + catch (int e) + { + cout << "caught integer exception: " << e << endl; + } + cout << "And what was the question?" << endl; + return 0; +} diff --git a/20230427/exceptions-2c.cpp b/20230427/exceptions-2c.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3d165103d4ad17eb97a55e44d8fc6ed2426f8d3d --- /dev/null +++ b/20230427/exceptions-2c.cpp @@ -0,0 +1,45 @@ +#include <iostream> + +using namespace std; + +void check_answer (int answer) +{ + if (answer == 42) + return; + try + { + if (answer == 10) + throw answer; + if (answer == 137) + throw "alpha"; + } + catch (int e) + { + cout << "Yeah!" << endl; + throw; + } + throw "bullshit"; +} + +int main () +{ + int answer; + cout << "What's your answer? "; + cin >> answer; + try + { + if (answer == 23) + throw answer; + check_answer (answer); + } + catch (const char *e) + { + cout << "caught string exception: " << e << endl; + } + catch (int e) + { + cout << "caught integer exception: " << e << endl; + } + cout << "And what was the question?" << endl; + return 0; +} diff --git a/20230427/exceptions-3.cpp b/20230427/exceptions-3.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9e5941ac486d6117005f5a89913814a50b39cf7f --- /dev/null +++ b/20230427/exceptions-3.cpp @@ -0,0 +1,42 @@ +#include <iostream> + +using namespace std; + +void check_answer (int answer) +{ + if (answer != 42) + { + try + { + if (answer == 10) + throw answer; + else if (answer == 137) + throw "alpha"; + } + catch (int e) + { + cout << "Yeah!" << endl; + } + throw "bullshit"; + } +} + +int main () +{ + int answer; + cout << "What's your answer? "; + cin >> answer; + try + { + if (answer == 23) + throw answer; + else + check_answer (answer); + } + catch (const char *e) + { + cout << "caught string exception: " << e << endl; + } + cout << "And what was the question?" << endl; + return 0; +} diff --git a/20230427/exceptions-4.cpp b/20230427/exceptions-4.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a20e5690c7d5b42283766cf9b454b528ea4594a8 --- /dev/null +++ b/20230427/exceptions-4.cpp @@ -0,0 +1,28 @@ +#include <iostream> + +using namespace std; + +class philosophy_exception: public exception +{ + int answer; +public: + philosophy_exception (int a) { answer = a; } +}; + +int main () +{ + int answer; + cout << "What's your answer? "; + cin >> answer; + try + { + if (answer != 42) + throw philosophy_exception (answer); + cout << "And what was the question?" << endl; + } + catch (exception &e) + { + cout << "caught exception" << endl; + } + return 0; +} diff --git a/20230427/exceptions-5.cpp b/20230427/exceptions-5.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f61ca5a43495ca4131a6e28bcd2cbedf2119b29f --- /dev/null +++ b/20230427/exceptions-5.cpp @@ -0,0 +1,33 @@ +#include <iostream> + +using namespace std; + +class philosophy_exception: public exception +{ + int answer; +public: + philosophy_exception (int a) { answer = a; } + int get_answer () { return answer; } +}; + +int main () +{ + int answer; + cout << "What's your answer? "; + cin >> answer; + try + { + if (answer != 42) + throw philosophy_exception (answer); + cout << "And what was the question?" << endl; + } + catch (philosophy_exception &e) + { + cout << "caught philosophy exception: " << e.get_answer () << endl; + } + catch (exception &e) + { + cout << "caught exception" << endl; + } + return 0; +} diff --git a/20230427/exceptions-6.cpp b/20230427/exceptions-6.cpp new file mode 100644 index 0000000000000000000000000000000000000000..326b7bca632c77958eaa6afbbab332efe76a86e5 --- /dev/null +++ b/20230427/exceptions-6.cpp @@ -0,0 +1,33 @@ +#include <iostream> + +using namespace std; + +class philosophy_exception: public exception +{ + int answer; +public: + philosophy_exception (int a) { answer = a; } + int get_answer () { return answer; } +}; + +int main () +{ + int answer; + cout << "What's your answer? "; + cin >> answer; + try + { + if (answer != 42) + throw philosophy_exception (answer); + cout << "And what was the question?" << endl; + } + catch (exception &e) + { + cout << "caught exception" << endl; + } + catch (philosophy_exception &e) + { + cout << "caught philosophy exception: " << e.get_answer () << endl; + } + return 0; +} diff --git a/20230427/exceptions-7.cpp b/20230427/exceptions-7.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6a8cf005e189ce42ce3df8df0ce3c53ab3adaa34 --- /dev/null +++ b/20230427/exceptions-7.cpp @@ -0,0 +1,38 @@ +#include <iostream> +#include <sstream> + +using namespace std; + +class philosophy_exception: public exception +{ + int answer; +public: + philosophy_exception (int a) { answer = a; } + virtual const char *what (); +}; + +const char *philosophy_exception::what () +{ + ostringstream buffer; + buffer << "philosophy exception #" << answer; + return buffer.str ().c_str (); +} + +int main () +{ + int answer; + cout << "What's your answer? "; + cin >> answer; + try + { + if (answer == 42) + cout << "And what was the question?" << endl; + else + throw philosophy_exception (answer); + } + catch (exception &e) + { + cout << "caught exception: " << e.what () << endl; + } + return 0; +} diff --git a/20230427/exceptions-8.cpp b/20230427/exceptions-8.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bf3e05ebdd4e42f25c35533198ad4663f4164455 --- /dev/null +++ b/20230427/exceptions-8.cpp @@ -0,0 +1,38 @@ +#include <iostream> +#include <sstream> + +using namespace std; + +class philosophy_exception: public exception +{ + int answer; +public: + philosophy_exception (int a) { answer = a; } + virtual const char *what () const noexcept; +}; + +const char *philosophy_exception::what () const noexcept +{ + ostringstream buffer; + buffer << "philosophy exception #" << answer; + return buffer.str ().c_str (); +} + +int main () +{ + int answer; + cout << "What's your answer? "; + cin >> answer; + try + { + if (answer == 42) + cout << "And what was the question?" << endl; + else + throw philosophy_exception (answer); + } + catch (exception &e) + { + cout << "caught exception: " << e.what () << endl; + } + return 0; +} diff --git a/20230427/exceptions-9.cpp b/20230427/exceptions-9.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0d0eca904e2257f7604a7e87a8337c533f8a1f19 --- /dev/null +++ b/20230427/exceptions-9.cpp @@ -0,0 +1,39 @@ +#include <iostream> +#include <sstream> + +using namespace std; + +class philosophy_exception: public exception +{ + int answer; +public: + philosophy_exception (int a) { answer = a; } + virtual const char *what () const noexcept; +}; + +const char *philosophy_exception::what () const noexcept +{ + return "Marvin"; +// ostringstream buffer; +// buffer << "philosophy exception #" << answer; +// return buffer.str ().c_str (); +} + +int main () +{ + int answer; + cout << "What's your answer? "; + cin >> answer; + try + { + if (answer == 42) + cout << "And what was the question?" << endl; + else + throw philosophy_exception (answer); + } + catch (exception &e) + { + cout << "caught exception: " << e.what () << endl; + } + return 0; +} diff --git a/20230427/exceptions-what.cpp b/20230427/exceptions-what.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d575cf20ce76e5d25ae137a8d8420730400efc94 --- /dev/null +++ b/20230427/exceptions-what.cpp @@ -0,0 +1,16 @@ +// exception::what +#include <iostream> // std::cout +#include <exception> // std::exception + +struct ooops : std::exception { + virtual const char* what() const noexcept {return "Ooops!\n";} +}; + +int main () { + try { + throw ooops(); + } catch (std::exception& ex) { + std::cout << ex.what(); + } + return 0; +} diff --git a/20230427/r-value-references-01.cpp b/20230427/r-value-references-01.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0be06b977c2dcf420c879f652ab0dae78f80467b --- /dev/null +++ b/20230427/r-value-references-01.cpp @@ -0,0 +1,46 @@ +#include <iostream> +#include <string> + +using namespace std; + +class TComplicated +{ + string *content; + +public: + TComplicated () + { + content = NULL; + } + + TComplicated (const char *content) + { + this->content = new string (content); + } + + ~TComplicated () + { + cout << "~TComplicated (): content = "; + print (); + if (content) + delete content; + content = NULL; + } + + void print () + { + if (content) + cout << *content << endl; + else + cout << "(NULL)" << endl; + } +}; + +int main () +{ + TComplicated c = "Hello, world!"; + c.print (); + TComplicated d; + d.print (); + return 0; +} diff --git a/20230427/r-value-references-02.cpp b/20230427/r-value-references-02.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5477fbad2e6784fdeca06b39dec9eecfcd0a9a59 --- /dev/null +++ b/20230427/r-value-references-02.cpp @@ -0,0 +1,54 @@ +#include <iostream> +#include <string> + +using namespace std; + +class TComplicated +{ + string *content; + +public: + TComplicated () + { + content = NULL; + } + + TComplicated (const char *content) + { + this->content = new string (content); + } + + TComplicated (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + } + + ~TComplicated () + { + cout << "~TComplicated (): content = "; + print (); + if (content) + delete content; + content = NULL; + } + + void print () + { + if (content) + cout << *content << endl; + else + cout << "(NULL)" << endl; + } +}; + +int main () +{ + TComplicated c = "Hello, world!"; + c.print (); + TComplicated d = c; + d.print (); + return 0; +} diff --git a/20230427/r-value-references-03.cpp b/20230427/r-value-references-03.cpp new file mode 100644 index 0000000000000000000000000000000000000000..35be424c2f9ec9fcbd3370ad18332995eff7cff9 --- /dev/null +++ b/20230427/r-value-references-03.cpp @@ -0,0 +1,57 @@ +#include <iostream> +#include <string> + +using namespace std; + +class TComplicated +{ + string *content; + +public: + TComplicated () + { + content = NULL; + } + + TComplicated (const char *content) + { + this->content = new string (content); + } + + TComplicated (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + } + + ~TComplicated () + { + cout << "~TComplicated (): content = "; + print (); + if (content) + delete content; + content = NULL; + } + + void print () + { + if (content) + cout << *content << endl; + else + cout << "(NULL)" << endl; + } +}; + +void foo (TComplicated x) +{ + x.print (); +} + +int main () +{ + TComplicated c = "Hello, world!"; + foo (c); + return 0; +} diff --git a/20230427/r-value-references-03a.cpp b/20230427/r-value-references-03a.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4ad6e9930fd8ce1ea5004440a6d99e1b141377eb --- /dev/null +++ b/20230427/r-value-references-03a.cpp @@ -0,0 +1,57 @@ +#include <iostream> +#include <string> + +using namespace std; + +class TComplicated +{ + string *content; + +public: + TComplicated () + { + content = NULL; + } + + TComplicated (const char *content) + { + this->content = new string (content); + } + + TComplicated (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + } + + ~TComplicated () + { + cout << "~TComplicated (): content = "; + print (); + if (content) + delete content; + content = NULL; + } + + void print () + { + if (content) + cout << *content << endl; + else + cout << "(NULL)" << endl; + } +}; + +void foo (TComplicated &x) +{ + x.print (); +} + +int main () +{ + TComplicated c = "Hello, world!"; + foo (c); + return 0; +} diff --git a/20230427/r-value-references-04.cpp b/20230427/r-value-references-04.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e7b04d87e8bb8cc9bf74a3e55ae2698fbba416de --- /dev/null +++ b/20230427/r-value-references-04.cpp @@ -0,0 +1,54 @@ +#include <iostream> +#include <string> + +using namespace std; + +class TComplicated +{ + string *content; + +public: + TComplicated () + { + content = NULL; + } + + TComplicated (const char *content) + { + this->content = new string (content); + } + + TComplicated (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + } + + ~TComplicated () + { + cout << "~TComplicated (): content = "; + print (); + if (content) + delete content; + content = NULL; + } + + void print () + { + if (content) + cout << *content << endl; + else + cout << "(NULL)" << endl; + } +}; + +int main () +{ + TComplicated c = "Hello, world!"; + c.print (); + TComplicated d = move (c); + d.print (); + return 0; +} diff --git a/20230427/r-value-references-04a.cpp b/20230427/r-value-references-04a.cpp new file mode 100644 index 0000000000000000000000000000000000000000..686fae7cfaa6e7b19a5d18840501c4f2833af440 --- /dev/null +++ b/20230427/r-value-references-04a.cpp @@ -0,0 +1,54 @@ +#include <iostream> +#include <string> + +using namespace std; + +class TComplicated +{ + string *content; + +public: + TComplicated () + { + content = NULL; + } + + TComplicated (const char *content) + { + this->content = new string (content); + } + + TComplicated (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + } + + ~TComplicated () + { + cout << "~TComplicated (): content = "; + print (); + if (content) + delete content; + content = NULL; + } + + void print () + { + if (content) + cout << *content << endl; + else + cout << "(NULL)" << endl; + } +}; + +int main () +{ + TComplicated c = "Hello, world!"; + TComplicated d = move (c); + c.print (); + d.print (); + return 0; +} diff --git a/20230427/r-value-references-05.cpp b/20230427/r-value-references-05.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cd82834382d06914a97e4f05b997476770d02acb --- /dev/null +++ b/20230427/r-value-references-05.cpp @@ -0,0 +1,60 @@ +#include <iostream> +#include <string> + +using namespace std; + +const bool something_really_complicated = true; + +class TComplicated +{ + string *content; + +public: + TComplicated () + { + content = NULL; + } + + TComplicated (const char *content) + { + this->content = new string (content); + } + + TComplicated (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + } + + ~TComplicated () + { + cout << "~TComplicated (): content = "; + print (); + if (content) + delete content; + content = NULL; + } + + void print () + { + if (content) + cout << *content << endl; + else + cout << "(NULL)" << endl; + } +}; + +int main () +{ + TComplicated d; + if (something_really_complicated) + { + TComplicated c = "Hello, world!"; + c.print (); + d = c; + } + d.print (); + return 0; +} diff --git a/20230427/r-value-references-06.cpp b/20230427/r-value-references-06.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f5653e3f064b813c83bec63d7ffa7344f15caa46 --- /dev/null +++ b/20230427/r-value-references-06.cpp @@ -0,0 +1,69 @@ +#include <iostream> +#include <string> + +using namespace std; + +const bool something_really_complicated = true; + +class TComplicated +{ + string *content; + +public: + TComplicated () + { + content = NULL; + } + + TComplicated (const char *content) + { + this->content = new string (content); + } + + TComplicated (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + } + + ~TComplicated () + { + cout << "~TComplicated (): content = "; + print (); + if (content) + delete content; + content = NULL; + } + + TComplicated &operator = (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + return *this; + } + + void print () + { + if (content) + cout << *content << endl; + else + cout << "(NULL)" << endl; + } +}; + +int main () +{ + TComplicated d; + if (something_really_complicated) + { + TComplicated c = "Hello, world!"; + c.print (); + d = c; + } + d.print (); + return 0; +} diff --git a/20230427/r-value-references-07.cpp b/20230427/r-value-references-07.cpp new file mode 100644 index 0000000000000000000000000000000000000000..690be43028b0216ae74b27beb65f050b7425c477 --- /dev/null +++ b/20230427/r-value-references-07.cpp @@ -0,0 +1,69 @@ +#include <iostream> +#include <string> + +using namespace std; + +const bool something_really_complicated = true; + +class TComplicated +{ + string *content; + +public: + TComplicated () + { + content = NULL; + } + + TComplicated (const char *content) + { + this->content = new string (content); + } + + TComplicated (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + } + + ~TComplicated () + { + cout << "~TComplicated (): content = "; + print (); + if (content) + delete content; + content = NULL; + } + + TComplicated &operator = (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + return *this; + } + + void print () + { + if (content) + cout << *content << endl; + else + cout << "(NULL)" << endl; + } +}; + +int main () +{ + TComplicated d; + if (something_really_complicated) + { + TComplicated c = "Hello, world!"; + c.print (); + d = move (c); + } + d.print (); + return 0; +} diff --git a/20230427/r-value-references-08.cpp b/20230427/r-value-references-08.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7a6de9003cc849a4123b6f22bdeafcfec4306140 --- /dev/null +++ b/20230427/r-value-references-08.cpp @@ -0,0 +1,76 @@ +#include <iostream> +#include <string> + +using namespace std; + +const bool something_really_complicated = true; + +class TComplicated +{ + string *content; + +public: + TComplicated () + { + content = NULL; + } + + TComplicated (const char *content) + { + this->content = new string (content); + } + + TComplicated (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + } + + ~TComplicated () + { + cout << "~TComplicated (): content = "; + print (); + if (content) + delete content; + content = NULL; + } + + TComplicated &operator = (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + return *this; + } + + TComplicated &operator = (TComplicated &&src) + { + this->content = src.content; + src.content = NULL; + return *this; + } + + void print () + { + if (content) + cout << *content << endl; + else + cout << "(NULL)" << endl; + } +}; + +int main () +{ + TComplicated d; + if (something_really_complicated) + { + TComplicated c = "Hello, world!"; + c.print (); + d = move (c); + } + d.print (); + return 0; +} diff --git a/20230427/r-value-references-09.cpp b/20230427/r-value-references-09.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fba9c1cab79269d879f19119aad0f03aa4262ac8 --- /dev/null +++ b/20230427/r-value-references-09.cpp @@ -0,0 +1,76 @@ +#include <iostream> +#include <string> + +using namespace std; + +const bool something_really_complicated = true; + +class TComplicated +{ + string *content; + +public: + TComplicated () + { + content = NULL; + } + + TComplicated (const char *content) + { + this->content = new string (content); + } + + TComplicated (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + } + + ~TComplicated () + { + cout << "~TComplicated (): content = "; + print (); + if (content) + delete content; + content = NULL; + } + + TComplicated &operator = (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + return *this; + } + + TComplicated &operator = (TComplicated &&src) + { + this->content = src.content; + src.content = NULL; + return *this; + } + + void print () + { + if (content) + cout << *content << endl; + else + cout << "(NULL)" << endl; + } +}; + +int main () +{ + TComplicated d; + if (something_really_complicated) + { + TComplicated c = "Hello, world!"; + c.print (); + d = c; + } + d.print (); + return 0; +} diff --git a/20230427/r-value-references-10.cpp b/20230427/r-value-references-10.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bab07b5da43a4ce5e61a003bbeb138aa8aea59d1 --- /dev/null +++ b/20230427/r-value-references-10.cpp @@ -0,0 +1,76 @@ +#include <iostream> +#include <string> + +using namespace std; + +const bool something_really_complicated = true; + +class TComplicated +{ + string *content; + +public: + TComplicated () + { + content = NULL; + } + + TComplicated (const char *content) + { + this->content = new string (content); + } + + TComplicated (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + } + + ~TComplicated () + { + cout << "~TComplicated (): content = "; + print (); + if (content) + delete content; + content = NULL; + } + + TComplicated &operator = (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + return *this; + } + + TComplicated &operator = (TComplicated &&src) + { + this->content = src.content; + src.content = NULL; + return *this; + } + + void print () + { + if (content) + cout << *content << endl; + else + cout << "(NULL)" << endl; + } +}; + +int main () +{ + TComplicated d; + if (something_really_complicated) + { + TComplicated c = "Hello, world!"; + c.print (); + d = (TComplicated &&) c; + } + d.print (); + return 0; +} diff --git a/20230427/r-value-references-11.cpp b/20230427/r-value-references-11.cpp new file mode 100644 index 0000000000000000000000000000000000000000..253e7547b2486ed9c1bef096535bfc3eb747bfc4 --- /dev/null +++ b/20230427/r-value-references-11.cpp @@ -0,0 +1,77 @@ +#include <iostream> +#include <string> + +using namespace std; + +const bool something_really_complicated = true; + +class TComplicated +{ + string *content; + +public: + TComplicated () + { + content = NULL; + } + + TComplicated (const char *content) + { + this->content = new string (content); + } + + TComplicated (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + } + + ~TComplicated () + { + cout << "~TComplicated (): content = "; + print (); + if (content) + delete content; + content = NULL; + } + + TComplicated &operator = (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + return *this; + } + + void move (TComplicated &src) + { + if (content) + delete content; + this->content = src.content; + src.content = NULL; + } + + void print () + { + if (content) + cout << *content << endl; + else + cout << "(NULL)" << endl; + } +}; + +int main () +{ + TComplicated d; + if (something_really_complicated) + { + TComplicated c = "Hello, world!"; + c.print (); + d.move (c); + } + d.print (); + return 0; +} diff --git a/20230427/r-value-references-12.cpp b/20230427/r-value-references-12.cpp new file mode 100644 index 0000000000000000000000000000000000000000..44524f706225e2d2aa7a0d33880809f7dcc7fe9f --- /dev/null +++ b/20230427/r-value-references-12.cpp @@ -0,0 +1,83 @@ +#include <iostream> +#include <string> + +using namespace std; + +const bool something_really_complicated = true; + +class TComplicated +{ + string *content; + +public: + TComplicated () + { + content = NULL; + } + + TComplicated (const char *content) + { + this->content = new string (content); + } + + TComplicated (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + } + + ~TComplicated () + { + cout << "~TComplicated (): content = "; + print (); + if (content) + delete content; + content = NULL; + } + + TComplicated &operator = (const TComplicated &src) + { + if (src.content) + this->content = new string (*src.content); + else + this->content = NULL; + return *this; + } + + string *purge_content () + { + string *save_content = content; + content = NULL; + return save_content; + } + + void move (TComplicated &src) + { + if (content) + delete content; + this->content = src.purge_content (); + } + + void print () + { + if (content) + cout << *content << endl; + else + cout << "(NULL)" << endl; + } +}; + +int main () +{ + TComplicated d; + if (something_really_complicated) + { + TComplicated c = "Hello, world!"; + c.print (); + d.move (c); + } + d.print (); + return 0; +} diff --git a/20230427/type-conversions-01.cpp b/20230427/type-conversions-01.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f861606d9525fe4e28bad6edbec88c29a1da68f0 --- /dev/null +++ b/20230427/type-conversions-01.cpp @@ -0,0 +1,11 @@ +#include <stdio.h> +#include <stdint.h> +#include <inttypes.h> + +int main () +{ + const char *hello = "Hello, world!"; + uint64_t address = (uint64_t) hello; + printf ("%" PRIx64 "\n", address); + return 0; +} diff --git a/20230427/type-conversions-02.cpp b/20230427/type-conversions-02.cpp new file mode 100644 index 0000000000000000000000000000000000000000..be702cc1f9de8a45d7d030e28172636d4cd663d5 --- /dev/null +++ b/20230427/type-conversions-02.cpp @@ -0,0 +1,11 @@ +#include <stdio.h> +#include <stdint.h> +#include <inttypes.h> + +int main () +{ + const char *hello = "Hello, world!"; + uint64_t address = uint64_t (hello); + printf ("%" PRIx64 "\n", address); + return 0; +} diff --git a/20230427/type-conversions-03.cpp b/20230427/type-conversions-03.cpp new file mode 100644 index 0000000000000000000000000000000000000000..34572937e5194527db8c81746205cec0469ae129 --- /dev/null +++ b/20230427/type-conversions-03.cpp @@ -0,0 +1,24 @@ +#include <stdio.h> + +struct TBase +{ + virtual void print () + { + printf ("(Base)\n"); + } +}; + +struct THello: public TBase +{ + virtual void print () + { + printf ("Hello, world!\n"); + } +}; + +int main () +{ + TBase *p = new THello; + p->print (); + return 0; +} diff --git a/20230427/type-conversions-04.cpp b/20230427/type-conversions-04.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e21b9c100d88449a17b5883a5d52da04c71a81bc --- /dev/null +++ b/20230427/type-conversions-04.cpp @@ -0,0 +1,24 @@ +#include <stdio.h> + +struct TBase +{ + void print () + { + printf ("(Base)\n"); + } +}; + +struct THello: public TBase +{ + void print () + { + printf ("Hello, world!\n"); + } +}; + +int main () +{ + TBase *p = new THello; + p->print (); + return 0; +} diff --git a/20230427/type-conversions-05.cpp b/20230427/type-conversions-05.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ea77aecb3c95a10ae6adf322cda448fa0f5e89c4 --- /dev/null +++ b/20230427/type-conversions-05.cpp @@ -0,0 +1,25 @@ +#include <stdio.h> + +struct TBase +{ + virtual void print () + { + printf ("(Base)\n"); + } +}; + +struct THello: public TBase +{ + virtual void print () + { + printf ("Hello, world!\n"); + } +}; + +int main () +{ + TBase *p = new THello; + THello *q = p; + q->print (); + return 0; +} diff --git a/20230427/type-conversions-06.cpp b/20230427/type-conversions-06.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5e969135dc33cb4f380d68867dec60b05d65bb4d --- /dev/null +++ b/20230427/type-conversions-06.cpp @@ -0,0 +1,25 @@ +#include <stdio.h> + +struct TBase +{ + virtual void print () + { + printf ("(Base)\n"); + } +}; + +struct THello: public TBase +{ + virtual void print () + { + printf ("Hello, world!\n"); + } +}; + +int main () +{ + TBase *p = new THello; + THello *q = dynamic_cast <THello *> (p); + q->print (); + return 0; +} diff --git a/20230427/type-conversions-07.cpp b/20230427/type-conversions-07.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7454be7612da80fb38d8e96a6a871e8cb5ce72c6 --- /dev/null +++ b/20230427/type-conversions-07.cpp @@ -0,0 +1,25 @@ +#include <stdio.h> + +struct TBase +{ + virtual void print () + { + printf ("(Base)\n"); + } +}; + +struct THello: public TBase +{ + virtual void print () + { + printf ("Hello, world!\n"); + } +}; + +int main () +{ + TBase *p = new TBase; + THello *q = dynamic_cast <THello *> (p); + q->print (); + return 0; +} diff --git a/20230427/type-conversions-08.cpp b/20230427/type-conversions-08.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c01ddccee9360bd0b7d24bd9b1c6a57828bf3934 --- /dev/null +++ b/20230427/type-conversions-08.cpp @@ -0,0 +1,28 @@ +#include <stdio.h> + +struct TBase +{ + virtual void print () + { + printf ("(Base)\n"); + } +}; + +struct THello: public TBase +{ + virtual void print () + { + printf ("Hello, world!\n"); + } +}; + +int main () +{ + TBase *p = new TBase; + THello *q = dynamic_cast <THello *> (p); + if (q) + q->print (); + else + printf ("Typumwandlung fehlgeschlagen.\n"); + return 0; +} diff --git a/20230427/type-conversions-09.cpp b/20230427/type-conversions-09.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4aebad72e42a76c6ee2b41ac1924016890d186e7 --- /dev/null +++ b/20230427/type-conversions-09.cpp @@ -0,0 +1,28 @@ +#include <stdio.h> + +struct TBase +{ + virtual void print () + { + printf ("(Base)\n"); + } +}; + +struct THello: public TBase +{ + virtual void print () + { + printf ("Hello, world!\n"); + } +}; + +int main () +{ + TBase *p = new THello; + THello *q = dynamic_cast <THello *> (p); + if (q) + q->print (); + else + printf ("Typumwandlung fehlgeschlagen.\n"); + return 0; +} diff --git a/20230427/type-conversions-10.cpp b/20230427/type-conversions-10.cpp new file mode 100644 index 0000000000000000000000000000000000000000..416aa6e554911a1cb6862e53cbdf94df4cc7e8b6 --- /dev/null +++ b/20230427/type-conversions-10.cpp @@ -0,0 +1,28 @@ +#include <stdio.h> + +struct TBase +{ + virtual void print () + { + printf ("(Base)\n"); + } +}; + +struct THello: public TBase +{ + virtual void print () + { + printf ("Hello, world!\n"); + } +}; + +int main () +{ + TBase *p = new THello; + THello *q = static_cast <THello *> (p); + if (q) + q->print (); + else + printf ("Typumwandlung fehlgeschlagen.\n"); + return 0; +} diff --git a/20230427/type-conversions-11.cpp b/20230427/type-conversions-11.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a92b6bb182e14c3968ff32c1e771b8ae084d60f0 --- /dev/null +++ b/20230427/type-conversions-11.cpp @@ -0,0 +1,28 @@ +#include <stdio.h> + +struct TBase +{ + virtual void print () + { + printf ("(Base)\n"); + } +}; + +struct THello: public TBase +{ + virtual void print () + { + printf ("Hello, world!\n"); + } +}; + +int main () +{ + TBase *p = new TBase; + THello *q = static_cast <THello *> (p); + if (q) + q->print (); + else + printf ("Typumwandlung fehlgeschlagen.\n"); + return 0; +} diff --git a/20230427/type-conversions-12.cpp b/20230427/type-conversions-12.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bce43d1d16cd7c1026c415f2c05d04e8f918e426 --- /dev/null +++ b/20230427/type-conversions-12.cpp @@ -0,0 +1,29 @@ +#include <stdio.h> + +struct TBase +{ + virtual void print () + { + printf ("(Base)\n"); + } +}; + +struct THello: public TBase +{ + virtual void print () + { + printf ("Hello, world!\n"); + } +}; + +int main () +{ + int answer = 13; + int *p = &answer; + THello *q = static_cast <THello *> (p); + if (q) + q->print (); + else + printf ("Typumwandlung fehlgeschlagen.\n"); + return 0; +} diff --git a/20230427/type-conversions-13.cpp b/20230427/type-conversions-13.cpp new file mode 100644 index 0000000000000000000000000000000000000000..50a04d324603d78b5c0b99dad7bb4b2be522398f --- /dev/null +++ b/20230427/type-conversions-13.cpp @@ -0,0 +1,29 @@ +#include <stdio.h> + +struct TBase +{ + virtual void print () + { + printf ("(Base)\n"); + } +}; + +struct THello: public TBase +{ + virtual void print () + { + printf ("Hello, world!\n"); + } +}; + +int main () +{ + int answer = 13; + int *p = &answer; + THello *q = (THello *) p; + if (q) + q->print (); + else + printf ("Typumwandlung fehlgeschlagen.\n"); + return 0; +} diff --git a/20230427/type-conversions-14.cpp b/20230427/type-conversions-14.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a9ed970c9ef1cf65a7d89c12b4216929ac187bc5 --- /dev/null +++ b/20230427/type-conversions-14.cpp @@ -0,0 +1,31 @@ +#include <stdio.h> + +struct TBase +{ + virtual void print () + { + printf ("(Base)\n"); + } +}; + +struct THello: public TBase +{ + const char *content; + + THello (const char *s) + { + content = s; + } + + virtual void print () + { + printf ("%s\n", content); + } +}; + +int main () +{ + THello h = "Hello, world!"; + h.print (); + return 0; +} diff --git a/20230427/type-conversions-15.cpp b/20230427/type-conversions-15.cpp new file mode 100644 index 0000000000000000000000000000000000000000..17fa8b5119724a0c9da63eb0c6829064801ba106 --- /dev/null +++ b/20230427/type-conversions-15.cpp @@ -0,0 +1,37 @@ +#include <stdio.h> + +struct TBase +{ + virtual void print () + { + printf ("(Base)\n"); + } +}; + +struct THello: public TBase +{ + const char *content; + + THello (const char *s) + { + content = s; + } + + THello (const TBase &b) + { + content = "(Base)"; + } + + virtual void print () + { + printf ("%s\n", content); + } +}; + +int main () +{ + TBase b; + THello h = b; + h.print (); + return 0; +} diff --git a/20230427/type-conversions-16.cpp b/20230427/type-conversions-16.cpp new file mode 100644 index 0000000000000000000000000000000000000000..761cda5c89f4fd73fd14b6555b8aa9ebce7e2a3e --- /dev/null +++ b/20230427/type-conversions-16.cpp @@ -0,0 +1,37 @@ +#include <stdio.h> + +struct TBase +{ + virtual void print () + { + printf ("(Base)\n"); + } +}; + +struct THello: public TBase +{ + const char *content; + + THello (const char *s) + { + content = s; + } + + explicit THello (const TBase &b) + { + content = "(Base)"; + } + + virtual void print () + { + printf ("%s\n", content); + } +}; + +int main () +{ + TBase b; + THello h = b; + h.print (); + return 0; +} diff --git a/20230427/type-conversions-17.cpp b/20230427/type-conversions-17.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7f51b7f6d45792449bceee57905b07ae1756aca1 --- /dev/null +++ b/20230427/type-conversions-17.cpp @@ -0,0 +1,37 @@ +#include <stdio.h> + +struct TBase +{ + virtual void print () + { + printf ("(Base)\n"); + } +}; + +struct THello: public TBase +{ + const char *content; + + THello (const char *s) + { + content = s; + } + + explicit THello (const TBase &b) + { + content = "(Base)"; + } + + virtual void print () + { + printf ("%s\n", content); + } +}; + +int main () +{ + TBase b; + THello h (b); + h.print (); + return 0; +} diff --git a/20230427/type-conversions-18.cpp b/20230427/type-conversions-18.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bfab7be4086f699d4bbba83afbb72ddae0207d9e --- /dev/null +++ b/20230427/type-conversions-18.cpp @@ -0,0 +1,41 @@ +#include <stdio.h> + +struct TBase +{ + virtual void print () + { + printf ("(Base)\n"); + } +}; + +struct THello: public TBase +{ + const char *content; + + THello (const char *s) + { + content = s; + } + + THello (const TBase &b) + { + content = "(Base)"; + } + + virtual void print () + { + printf ("%s\n", content); + } +}; + +void print_it (const THello &h) +{ + printf ("%s\n", h.content); +} + +int main () +{ + TBase b; + print_it (b); + return 0; +} diff --git a/20230427/type-conversions-19.cpp b/20230427/type-conversions-19.cpp new file mode 100644 index 0000000000000000000000000000000000000000..32fe3fbff2115f30691f899950146559811092cb --- /dev/null +++ b/20230427/type-conversions-19.cpp @@ -0,0 +1,41 @@ +#include <stdio.h> + +struct TBase +{ + virtual void print () + { + printf ("(Base)\n"); + } +}; + +struct THello: public TBase +{ + const char *content; + + THello (const char *s) + { + content = s; + } + + explicit THello (const TBase &b) + { + content = "(Base)"; + } + + virtual void print () + { + printf ("%s\n", content); + } +}; + +void print_it (const THello &h) +{ + printf ("%s\n", h.content); +} + +int main () +{ + TBase b; + print_it (b); + return 0; +} diff --git a/20230427/type-conversions-20.cpp b/20230427/type-conversions-20.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cc5055de92ed51dd7fdb7372ef80e1a0e02a5fab --- /dev/null +++ b/20230427/type-conversions-20.cpp @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main () +{ + int answer = 1117; + int *p = &answer; + printf ("The address of the answer is: %zx\n", p); + return 0; +} diff --git a/20230427/type-conversions-21.cpp b/20230427/type-conversions-21.cpp new file mode 100644 index 0000000000000000000000000000000000000000..48cbdb94ecea46c10ddf74d1f1fd93f69ffe3b9b --- /dev/null +++ b/20230427/type-conversions-21.cpp @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main () +{ + int answer = 1117; + int *p = &answer; + printf ("The address of the answer is: %zx\n", (size_t) p); + return 0; +} diff --git a/20230427/type-conversions-22.cpp b/20230427/type-conversions-22.cpp new file mode 100644 index 0000000000000000000000000000000000000000..592c47f9135e4c8df84ecf4a8a0e8f05b38beccb --- /dev/null +++ b/20230427/type-conversions-22.cpp @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main () +{ + int answer = 1117; + int *p = &answer; + printf ("The address of the answer is: %zx\n", reinterpret_cast <size_t> (p)); + return 0; +} diff --git a/20230427/type-conversions-23.cpp b/20230427/type-conversions-23.cpp new file mode 100644 index 0000000000000000000000000000000000000000..45d2aeb563a5ebdbb151d8a8506c35c67d6a0687 --- /dev/null +++ b/20230427/type-conversions-23.cpp @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main () +{ + const char* hello = "Hello, world!"; + char *h = hello; + printf ("%s\n", h); + return 0; +} diff --git a/20230427/type-conversions-24.cpp b/20230427/type-conversions-24.cpp new file mode 100644 index 0000000000000000000000000000000000000000..889b4d5ab47ac8b867f36f2a45c9646b6c3f678f --- /dev/null +++ b/20230427/type-conversions-24.cpp @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main () +{ + const char* hello = "Hello, world!"; + char *h = (char *) hello; + printf ("%s\n", h); + return 0; +} diff --git a/20230427/type-conversions-25.cpp b/20230427/type-conversions-25.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fdb8227429c2e1a1fef71ad2cc853bd67e8670a7 --- /dev/null +++ b/20230427/type-conversions-25.cpp @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main () +{ + const char* hello = "Hello, world!"; + char *h = const_cast <char *> (hello); + printf ("%s\n", h); + return 0; +}