Modernes C++ programmieren

Okt 23, 2024

lst-0412-godb.cpp

//#(compile) c++; compiler:g132; options:-O3 -std=c++23; libs:-
// https://godbolt.org/z/TvKP7Ghvh 
#include <string>
#include <iostream>                      // cout
using std::string; using std::cout;

struct Value {
    int wert_;
    Value(int wert)                      // 1-Arg-Konstruktor = Typumwandlung
        : wert_{wert} {}
};

size_t laenge(string arg) {
    return arg.size();
}
Value doppel(Value v) {
    return Value{ v.wert_*2 };
}
int main() {
    cout << laenge("Hipphopp") << "\n";  // const char* in string
    cout << doppel(10).wert_ << "\n";    // int in Value
    string name {"Gandalf"};
    cout << ( name + " der Graue" ) << "\n"; // string + const char*
}