Operatorüberladung in C++ [] (Operatorüberladung in C++), Lektion, Seite 723731
https://www.purl.org/stefan_ram/pub/operatorueberladung_c++ (Permalink) ist die kanonische URI dieser Seite.
Stefan Ram
C++-Kurs

Operatorüberladung in C++ 

Ausdruck als Elementfunktion als freie Funktion

@a (a).operator@() operator@(a)

a@b (a).operator@(b) operator@(a,b)

a=b (a).operator=(b)

a[b] (a).operator[](b)

a-> (a).operator->()

a@ (a).operator@(0) operator@(a,0)

main.cpp

#include <initializer_list>
#include <ostream>
#include <iostream>
#include <vector>

using namespace ::std::literals;

template< class I >
static void print
( ::std::ostream & ostream, I const begin, I const top )
{ if( begin != top )
{ auto p = begin;
while( true )
{ ostream << *p++;
if( p == top )break;
ostream << ", "s; }}}

template< class C >
static inline ::std::ostream & operator <<
( ::std::ostream & ostream, ::std::vector< C > const & vector )
{ ::print( ostream, cbegin( vector ), cend( vector ));
return ostream; }

int main()
{ ::std::vector< int >v = { 27, 28, 29 };
::std::cout << v << '\n'; }

transcript
27, 28, 29

---

Seiteninformationen und Impressum   |   Mitteilungsformular  |   "ram@zedat.fu-berlin.de" (ohne die Anführungszeichen) ist die Netzpostadresse von Stefan Ram.   |   Eine Verbindung zur Stefan-Ram-Startseite befindet sich oben auf dieser Seite hinter dem Text "Stefan Ram".)  |   Der Urheber dieses Textes ist Stefan Ram. Alle Rechte sind vorbehalten. Diese Seite ist eine Veröffentlichung von Stefan Ram. Schlüsselwörter zu dieser Seite/relevant keywords describing this page: Stefan Ram Berlin slrprd slrprd stefanramberlin spellched stefanram723731 stefan_ram:723731 Operatorüberladung in C++ Stefan Ram, Berlin, and, or, near, uni, online, slrprd, slrprdqxx, slrprddoc, slrprd723731, slrprddef723731, PbclevtugFgrsnaEnz Erklärung, Beschreibung, Info, Information, Hinweis,

Der Urheber dieses Textes ist Stefan Ram. Alle Rechte sind vorbehalten. Diese Seite ist eine Veröffentlichung von Stefan Ram.
https://www.purl.org/stefan_ram/pub/operatorueberladung_c++