Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#7

Re: [c++] Durch Objektliste interieren

  Alt 13. Sep 2008, 20:25
Danke für deine Hilfe. Irgendwie komme ich nicht so ganz klar damit. Ich bekomme jetzt Syntaxfehler ohne Ende. Mein Quellcode:
Code:
#pragma once

#include <iostream>
#include <list>

#include "Konto.h"

class CKunde
{
private:
   string _name;
   string _vorname;
   list<CKonto> _konten;

   CKunde(void);
   ~CKunde(void);

public:
   string GetName();
   void SetName(string Name);
   string GetVorname();
   void SetVorname(string Vorname);
   list<CKonto> GetKonten();
   void AddKonto(CKonto* Konto);
};
Code:
#pragma once

#include <iostream>

class CKonto
{
private:
   string _beschreibung;
   int _saldo;

public:
   CKonto(void);
   ~CKonto(void);

   string GetBeschreibung();
   void SetBeschreibung(string Beschreibung);

   int GetSaldo();
   void SetSaldo(int Saldo);
};
Code:
// Bank.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "kunde.h"
#include <iterator>

using namespace std

int _tmain(int argc, _TCHAR* argv[])
{

   list<CKunde>_kunden;
   
   // class CKunde kunde1();

   CKunde* kunde1 = new CKunde();
   kunde1->SetName("Mueller");
   kunde1->SetVorname("Emil");
   CKonto* konto1 = new CKonto();
   konto1->SetBeschreibung("Privatkonto");
   konto1->SetSaldo(500);
   kunde1->AddKonto(konto1);
   CKonto* konto2 = new CKonto();
   konto2->SetBeschreibung("Firmenkonto");
   konto2->SetSaldo(1000);
   _kunden.push_back(*kunde1);
   
   list<CKunde>::iterator iterKunden;
   for(iterKunden = _kunden.begin(); iterKunden != _kunden.end(); ++iterKunden)
   {
      cout << iterKunden->GetName().c_str() << ", " << iterKunden->GetVorname().c_str() << endl;
      list<CKonto>::iterator iterKonten;
      for(iterKonten = iterKunden->GetKonten().begin(); iterKonten != iterKunden->GetKonten().end(); ++iterKonten)
      {
         cout << iterKonten->GetBeschreibung().c_str() << endl;
         cout << iterKonten->GetSaldo() << endl;
      }
      cout << endl;
   }

   return 0;
}
Und die Ausgabe des Compilers:
Code:
------ Erstellen gestartet: Projekt: Bank, Konfiguration: Debug Win32 ------
Compiling...
Bank.cpp
e:\c\programme\bank\konto.h(8) : error C2146: syntax error : missing ';' before identifier '_beschreibung'
e:\c\programme\bank\konto.h(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\konto.h(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\konto.h(15) : error C2146: syntax error : missing ';' before identifier 'GetBeschreibung'
e:\c\programme\bank\konto.h(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\konto.h(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\konto.h(15) : warning C4183: 'GetBeschreibung': missing return type; assumed to be a member function returning 'int'
e:\c\programme\bank\konto.h(16) : error C2061: syntax error : identifier 'string'
e:\c\programme\bank\kunde.h(11) : error C2146: syntax error : missing ';' before identifier '_name'
e:\c\programme\bank\kunde.h(11) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(11) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(12) : error C2146: syntax error : missing ';' before identifier '_vorname'
e:\c\programme\bank\kunde.h(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(13) : error C2143: syntax error : missing ';' before '<'
e:\c\programme\bank\kunde.h(13) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(13) : error C2238: unexpected token(s) preceding ';'
e:\c\programme\bank\kunde.h(19) : error C2146: syntax error : missing ';' before identifier 'GetName'
e:\c\programme\bank\kunde.h(19) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(19) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(19) : warning C4183: 'GetName': missing return type; assumed to be a member function returning 'int'
e:\c\programme\bank\kunde.h(20) : error C2061: syntax error : identifier 'string'
e:\c\programme\bank\kunde.h(21) : error C2146: syntax error : missing ';' before identifier 'GetVorname'
e:\c\programme\bank\kunde.h(21) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(21) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(21) : warning C4183: 'GetVorname': missing return type; assumed to be a member function returning 'int'
e:\c\programme\bank\kunde.h(22) : error C2061: syntax error : identifier 'string'
e:\c\programme\bank\kunde.h(23) : error C2143: syntax error : missing ';' before '<'
e:\c\programme\bank\kunde.h(23) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(23) : error C2238: unexpected token(s) preceding ';'
e:\c\programme\bank\bank.cpp(10) : error C2144: syntax error : 'int' should be preceded by ';'
e:\c\programme\bank\bank.cpp(17) : error C2248: 'CKunde::CKunde' : cannot access private member declared in class 'CKunde'
        e:\c\programme\bank\kunde.h(15) : see declaration of 'CKunde::CKunde'
        e:\c\programme\bank\kunde.h(9) : see declaration of 'CKunde'
e:\c\programme\bank\bank.cpp(18) : error C2660: 'CKunde::SetName' : function does not take 1 arguments
e:\c\programme\bank\bank.cpp(19) : error C2660: 'CKunde::SetVorname' : function does not take 1 arguments
e:\c\programme\bank\bank.cpp(21) : error C2660: 'CKonto::SetBeschreibung' : function does not take 1 arguments
e:\c\programme\bank\bank.cpp(25) : error C2660: 'CKonto::SetBeschreibung' : function does not take 1 arguments
e:\c\programme\bank\bank.cpp(32) : error C2228: left of '.c_str' must have class/struct/union
        type is 'int'
e:\c\programme\bank\bank.cpp(32) : error C2228: left of '.c_str' must have class/struct/union
        type is 'int'
e:\c\programme\bank\bank.cpp(34) : error C2039: 'GetKonten' : is not a member of 'CKunde'
        e:\c\programme\bank\kunde.h(9) : see declaration of 'CKunde'
e:\c\programme\bank\bank.cpp(34) : error C2228: left of '.begin' must have class/struct/union
e:\c\programme\bank\bank.cpp(34) : error C2039: 'GetKonten' : is not a member of 'CKunde'
        e:\c\programme\bank\kunde.h(9) : see declaration of 'CKunde'
e:\c\programme\bank\bank.cpp(34) : error C2228: left of '.end' must have class/struct/union
e:\c\programme\bank\bank.cpp(36) : error C2228: left of '.c_str' must have class/struct/union
        type is 'int'
Konto.cpp
e:\c\programme\bank\konto.h(8) : error C2146: syntax error : missing ';' before identifier '_beschreibung'
e:\c\programme\bank\konto.h(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\konto.h(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\konto.h(15) : error C2146: syntax error : missing ';' before identifier 'GetBeschreibung'
e:\c\programme\bank\konto.h(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\konto.h(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\konto.h(15) : warning C4183: 'GetBeschreibung': missing return type; assumed to be a member function returning 'int'
e:\c\programme\bank\konto.h(16) : error C2061: syntax error : identifier 'string'
e:\c\programme\bank\konto.cpp(16) : error C2556: 'std::string CKonto::GetBeschreibung(void)' : overloaded function differs only by return type from 'int CKonto::GetBeschreibung(void)'
        e:\c\programme\bank\konto.h(15) : see declaration of 'CKonto::GetBeschreibung'
e:\c\programme\bank\konto.cpp(16) : error C2371: 'CKonto::GetBeschreibung' : redefinition; different basic types
        e:\c\programme\bank\konto.h(15) : see declaration of 'CKonto::GetBeschreibung'
e:\c\programme\bank\konto.cpp(17) : error C2065: '_beschreibung' : undeclared identifier
e:\c\programme\bank\konto.cpp(21) : error C2511: 'void CKonto::SetBeschreibung(std::string)' : overloaded member function not found in 'CKonto'
        e:\c\programme\bank\konto.h(6) : see declaration of 'CKonto'
Kunde.cpp
e:\c\programme\bank\konto.h(8) : error C2146: syntax error : missing ';' before identifier '_beschreibung'
e:\c\programme\bank\konto.h(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\konto.h(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\konto.h(15) : error C2146: syntax error : missing ';' before identifier 'GetBeschreibung'
e:\c\programme\bank\konto.h(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\konto.h(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\konto.h(15) : warning C4183: 'GetBeschreibung': missing return type; assumed to be a member function returning 'int'
e:\c\programme\bank\konto.h(16) : error C2061: syntax error : identifier 'string'
e:\c\programme\bank\kunde.h(11) : error C2146: syntax error : missing ';' before identifier '_name'
e:\c\programme\bank\kunde.h(11) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(11) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(12) : error C2146: syntax error : missing ';' before identifier '_vorname'
e:\c\programme\bank\kunde.h(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(13) : error C2143: syntax error : missing ';' before '<'
e:\c\programme\bank\kunde.h(13) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(13) : error C2238: unexpected token(s) preceding ';'
e:\c\programme\bank\kunde.h(19) : error C2146: syntax error : missing ';' before identifier 'GetName'
e:\c\programme\bank\kunde.h(19) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(19) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(19) : warning C4183: 'GetName': missing return type; assumed to be a member function returning 'int'
e:\c\programme\bank\kunde.h(20) : error C2061: syntax error : identifier 'string'
e:\c\programme\bank\kunde.h(21) : error C2146: syntax error : missing ';' before identifier 'GetVorname'
e:\c\programme\bank\kunde.h(21) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(21) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(21) : warning C4183: 'GetVorname': missing return type; assumed to be a member function returning 'int'
e:\c\programme\bank\kunde.h(22) : error C2061: syntax error : identifier 'string'
e:\c\programme\bank\kunde.h(23) : error C2143: syntax error : missing ';' before '<'
e:\c\programme\bank\kunde.h(23) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.h(23) : error C2238: unexpected token(s) preceding ';'
e:\c\programme\bank\kunde.cpp(14) : error C2143: syntax error : missing ';' before 'CKunde::GetName'
e:\c\programme\bank\kunde.cpp(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.cpp(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.cpp(16) : error C2065: '_name' : undeclared identifier
e:\c\programme\bank\kunde.cpp(19) : error C2146: syntax error : missing ')' before identifier 'Name'
e:\c\programme\bank\kunde.cpp(19) : error C2761: 'void CKunde::SetName(void)' : member function redeclaration not allowed
e:\c\programme\bank\kunde.cpp(19) : error C2059: syntax error : ')'
e:\c\programme\bank\kunde.cpp(20) : error C2143: syntax error : missing ';' before '{'
e:\c\programme\bank\kunde.cpp(20) : error C2447: '{' : missing function header (old-style formal list?)
e:\c\programme\bank\kunde.cpp(24) : error C2143: syntax error : missing ';' before 'CKunde::GetVorname'
e:\c\programme\bank\kunde.cpp(24) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.cpp(24) : error C2086: 'int string' : redefinition
        e:\c\programme\bank\kunde.cpp(14) : see declaration of 'string'
e:\c\programme\bank\kunde.cpp(25) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.cpp(26) : error C2065: '_vorname' : undeclared identifier
e:\c\programme\bank\kunde.cpp(29) : error C2146: syntax error : missing ')' before identifier 'Vorname'
e:\c\programme\bank\kunde.cpp(29) : error C2761: 'void CKunde::SetVorname(void)' : member function redeclaration not allowed
e:\c\programme\bank\kunde.cpp(29) : error C2059: syntax error : ')'
e:\c\programme\bank\kunde.cpp(30) : error C2143: syntax error : missing ';' before '{'
e:\c\programme\bank\kunde.cpp(30) : error C2447: '{' : missing function header (old-style formal list?)
e:\c\programme\bank\kunde.cpp(34) : error C2143: syntax error : missing ';' before '<'
e:\c\programme\bank\kunde.cpp(34) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\c\programme\bank\kunde.cpp(34) : error C2039: 'GetKonten' : is not a member of 'CKunde'
        e:\c\programme\bank\kunde.h(9) : see declaration of 'CKunde'
e:\c\programme\bank\kunde.cpp(35) : error C2143: syntax error : missing ';' before '{'
e:\c\programme\bank\kunde.cpp(35) : error C2447: '{' : missing function header (old-style formal list?)
e:\c\programme\bank\kunde.cpp(41) : error C2065: '_konten' : undeclared identifier
e:\c\programme\bank\kunde.cpp(41) : error C2228: left of '.push_back' must have class/struct/union
        type is ''unknown-type''
Generating Code...
Build log was saved at "file://e:\C\Programme\Bank\Debug\BuildLog.htm"
Bank - 104 error(s), 7 warning(s)
========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
Ich bin mir ziemlich sicher, dass da viele Folgefehler enthalten sind. Ausserdem erstellt mir das VS lauter Ordner im Projektverzeichnis wie *.pdb. Was sind das für Ordner und kann man das nicht irgendwie vermeiden? Das kenne ich bisher so nicht vom VC 6.0.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat