Hallo Andreas,
Vielleicht findet sich noch jemand, der eine
Version des Codes in State-of-the-Art-C++ postet?
Deine Variante nach C++ portiert:
#include <iostream>
#include <string>
class Metadata {
public:
// Default-Konstruktor
Metadata()
: bezeichnung(), zusatzinfo()
{
}
// Konstruktor mit Initialisierung (für std::string)
Metadata(const std::string& bezeichnung, const std::string& zusatzinfo)
: bezeichnung(bezeichnung), zusatzinfo(zusatzinfo)
{
}
// Konstruktor mit Initialisierung (für const char *)
Metadata(const char *bezeichnung, const char *zusatzinfo)
: bezeichnung(bezeichnung), zusatzinfo(zusatzinfo)
{
}
// Konstruktor mit Initialisierung (gemischt)
Metadata(const std::string& bezeichnung, const char *zusatzinfo)
: bezeichnung(bezeichnung), zusatzinfo(zusatzinfo)
{
}
// Konstruktor mit Initialisierung (gemischt)
Metadata(const char *bezeichnung, const std::string& zusatzinfo)
: bezeichnung(bezeichnung), zusatzinfo(zusatzinfo)
{
}
// Copy-Konstruktor
Metadata(const Metadata& o)
: bezeichnung(o.bezeichnung), zusatzinfo(o.zusatzinfo)
{
}
// Zuweisungsoperator
Metadata& operator=(const Metadata& o)
{
// self-assign ist kein Problem in diesem Fall
bezeichnung = o.bezeichnung;
zusatzinfo = o.zusatzinfo;
return *this;
}
// Destruktor hier nicht benötigt
// Felder (können hier Public sein)
std::string bezeichnung;
std::string zusatzinfo;
};
int main (int argc, char **argv)
{
Metadata m("Erste Zeile", "Die zweite Zeile ist viel zu lang");
std::cout << "m.bezeichnung = " << m.bezeichnung << '\n'
<< "m.zusatzinfo = " << m.zusatzinfo << std::endl;
m.bezeichnung = "Erste Zeile (modifiziert)";
std::cout << "m.bezeichnung = " << m.bezeichnung << '\n'
<< "m.zusatzinfo = " << m.zusatzinfo << std::endl;
// oder auf dem Heap
Metadata *m2 = new Metadata ("Dritte Zeile", "Die vierte Zeile ist viel zu lang");
std::cout << "m2->bezeichnung = " << m2->bezeichnung << '\n'
<< "m2->zusatzinfo = " << m2->zusatzinfo << std::endl;
delete m2;
return 0;
}
Viele Grüße,
Christian
--
Mein "Weblog" [RSS]
Using XSLT to create JSON output (Saxon-B 9.0 for Java)
»I don't believe you can call yourself a web developer until you've built an app that uses hyperlinks for deletion and have all your data deleted by a search bot.«
-- Kommentar bei TDWTF
Mein "Weblog" [RSS]
Using XSLT to create JSON output (Saxon-B 9.0 for Java)
»I don't believe you can call yourself a web developer until you've built an app that uses hyperlinks for deletion and have all your data deleted by a search bot.«
-- Kommentar bei TDWTF