Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Fragen zu Prüfungsaufgabe C++

Empfohlene Antworten

Veröffentlicht

Weiss jemand was an diesem Codebeispiel falsch ist ?

Syntaktisch ist er auf jeden Fall richtig, jedoch sollten hier mehrere Fehler zu finden sein.

Hoffe, dass mir da jemand unter die Arme greifen kann, hab nämlich keine Ahnung ^^

Das Programm muss übrigens keinen wirklich Zweck erfüllen.

Das einzige was ich bis jetzt "glaube" zu wissen ist, dass das Überladen für den Zuweisungsoperator für eine Tiefenkopie fehlt,

aber das kann nicht alles sein

#include <iostream>

using namespace std;

class B{

};


class A{

     int i;

     B * pB;

    public:

     A(): i(2) { pB = new B[10]; }

     void Ausgabe() { cout <<i<<endl; }

     ~A() { delete pB; }

};


void Func(A &af1, A af2) {

     af1.Ausgabe();

     af2.Ausgabe();

}


int main(){

      A a, b, *p = new A;

      a = b;

      Func(*p,a); 

      return 0;    

}

Bearbeitet von Tiji

Das einzige was ich bis jetzt "glaube" zu wissen ist, dass das Überladen für den Zuweisungsoperator für eine Tiefenkopie fehlt,
Da glaubst du richtig. Dazu gehört auch noch ein Copykonstruktor, der beim Kopieren von af2 aufgerufen wird.

Durch das fehlende delete von p gibt es ein Speicherleck.

Es muss delete[] pB sein.

Bearbeitet von Klotzkopp

Danke vielmals

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.