C++ Fehlermeldung E2294



  • Hi,
    ich mach mich gerade mit den Grundlagen des objektorientierten Programmierens
    vertraut und weil Google nichts vernünftiges(bzw. verständliches) ausgespuckt hat,
    setz ich meine ganze Hoffnung mal wieder auf euch.

    Weis jemand was schief läuft, wenn folgende Fehlermeldung erscheint??

    [C++ Fehler] Sparkonto.cpp( 58 ): E2294 Auf linker Seite der Struktur ist . oder .* erforderlich..

    header

    //---------------------------------------------------------------------------
    #ifndef Sparfunk
    #define Sparfunk
    #include <condefs.h>
    #include <iostream.h>
    #include <conio.h>
    #include <stdio.h>
    class Sparkonto
    {
       private:
          int    Nummer;
          string Kontoinhaber;
          double Kontostand;
          double Habenzinssatz;
       public:
          //Methoden
          double Anzahl;
          void   Einzahlung(double);
          void   Auszahlung(double);
          double ZeigeKontostand(void);
          void   Kontoauszug(void);
          void   Zinsberechnung(void);
          // Konstruktor Standardkonstruktur und überladener Konstruktor
           Sparkonto(void);
          Sparkonto (int, string, double, double);
    
          // Dekonstruktor
          ~ Sparkonto();
    };
    //---------------------------------------------------------------------------
    #endif
    

    Unit

    //---------------------------------------------------------------------------
    #pragma hdrstop
    #include <H:\Ct\C++ 13\Objektorientiert\Include\sparheader.h>
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    
    Sparkonto::Sparkonto()
    {
    Anzahl++;
    Nummer = Anzahl;
    Kontoinhaber = "Unbekannt";
    Kontostand = 0.0;
    Habenzinssatz = 2.0;
    return;
    }
    Sparkonto::Sparkonto (int Nr, string Kto_inh, double Kto_stand, double Zinssatz)
    {
            Anzahl++;
            Nummer = Anzahl;
            Kontoinhaber = Kto_inh;
            Kontostand = Kto_stand;
            Habenzinssatz = Zinssatz;
    }
    Sparkonto::~Sparkonto()
    {
    }
    void Sparkonto::Einzahlung(double E)
    {
    Kontostand = Kontostand + E;
    }
    void Sparkonto::Auszahlung(double E)
    {
    Kontostand = Kontostand - E;
    }
    void Sparkonto::Zinsberechnung(void)
    {
    Kontostand = Kontostand + Kontostand*Habenzinssatz/100;
    cout << "Neuer Kontostand: " << Kontostand << "nach einer Zinserhöhung\n\n";
    }
    double Sparkonto::ZeigeKontostand(void)
    {
    return Kontostand;
    }
    void Sparkonto::Kontoauszug(void)
    {
    cout << "############### Kontoauszug ################" << "\n\n";
    cout << "Kontonummer:      " << Nummer << "\n\n";
    cout << "Kontoinhaber:     " << Kontoinhaber << "\n\n";
    cout << "Kontostand:       " << Kontostand << "\n\n";
    cout << "Habenzinssatz:    " << Habenzinssatz << "\n\n";
    cout << "############ Kontoauszug  Ende #############" << "\n\n";
    }
    

    main

    #pragma hdrstop
    #include <condefs.h>
    #include <iostream.h>
    #include <H:\Ct\C++ 13\Objektorientiert\Include\sparheader.h>
    #include <conio.h>
    #include <stdio.h>
    
    //---------------------------------------------------------------------------
    USEUNIT("H:\Ct\C++ 13\Objektorientiert\Sparkonto\sparkonto_methoden.cpp");
    //---------------------------------------------------------------------------
    #pragma argsused
    int main(int argc, char* argv[])
    {
    double Konto_Einzahl, d;
    
    // Sparkonto Maier anlegen
    
    Sparkonto Sparkonto1(1,"Maier", 5000.00, 2.0);
    
    //Einzahlungsabfrage
    
    cout << "Bitte Einzahlung eingeben: ";
    cin >> Konto_Einzahl;
    Sparkonto1.Einzahlung(Konto_Einzahl);
    
    //Kontostandausgabe
    
    d = Sparkonto1.ZeigeKontostand();
    cout << "Aktueller Kontostand: " << d << "\n\n";
    
    //Kontostand erleichtern
    
    cout << "Bitte Auszahlung eingeben: ";
    cin >> Konto_Einzahl;
    Sparkonto1.Auszahlung(Konto_Einzahl);
    
    //Kontostand anzeigen
    
    d = Sparkonto1.ZeigeKontostand();
    cout << "Aktueller Kontostand: " << d << "\n\n";
    
    //Zinsberechnung
    
    Sparkonto1.Zinsberechnung();
    
    //Kontoauszug
    
    Sparkonto1.Kontoauszug();
    
    //Annonymes Sparkonto anlegen
    
    Sparkonto Sparkonto2();
    
    //Kontostand ausgeben
    
    d = Sparkonto2.ZeigeKontostand();
    cout << "Aktueller Kontostand: " << d << "\n\n";
    
            getch();
            return 0;
    }
    


  • Wenn man ein Objekt über den Defaultkonstruktor konstruieren will, lautet die Syntax:

    Sparkonto k;
    // nicht: Sparkonto k();
    

    Das Auskommentierte wird syntaktisch als Funktionsdeklaration aufgefasst, deshalb wundert sich der Compiler, wieso du auf einmal den .-Operator auf eine Funktion anwenden willst.

    BTW es heißt Destruktor, nicht Dekonstruktor.


Anmelden zum Antworten