Facebook
From Reliable Curlew, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 113
  1. // TODO: Napisz przeładowania funkcji print dla struktury Book (przekazanie przez wartość, stałą wartość, referencję, stałą referencję, wskaźnik, wskaźnik do stałego obiektu)
  2.  
  3. struct Book {
  4.     string title;
  5.     int year;
  6. };
  7.  
  8. void print(Book book) {
  9.     /*wypisuje Book przez wartość*/
  10.     cout << "Title: " << book.title << endl;
  11.     cout << "Year: " << book.year << endl;
  12. }
  13.  
  14.  //nie działa bo przecież to to samo co wyżej
  15. void print(const Book book)
  16. {
  17.     cout << "Title: " << book.title << endl;
  18.     cout << "Year: " << book.year << endl;
  19. }
  20.  
  21. void print(Book &book) {
  22.     /*wypisuje Book przez referencję*/
  23.     cout << "Title: " << book.title << endl;
  24.     cout << "Year: " << book.year << endl;
  25. }
  26.  
  27. void print(const Book &book) {
  28.     /*wypisuje Book przez stałą referencję*/
  29.     cout << "Title: " << book.title << endl;
  30.     cout << "Year: " << book.year << endl;
  31. }
  32.  
  33. void print(Book *book) {
  34.     /*wypisuje Book przez wskaźnik*/
  35.     cout << "Title: " << book->title << endl;
  36.     cout << "Year: " << book->year << endl;
  37. }
  38.  
  39. void print(const Book *book) {
  40.     /*wypisuje Book przez stały wskaźnik*/
  41.     cout << "Title: " << book->title << endl;
  42.     cout << "Year: " << book->year << endl;
  43. }

Replies to Untitled rss

Title Name Language When
Re: Untitled Thundering Flamingo cpp 3 Years ago.