Ich beschäftige mich gerade mit der Objektorientierten Programmierung in c++.
Ich habe eine Konto Klasse mit dem Feld account und den Methoden void setMoney(float value) //einzahlen
float getMoney(float value) //auszahlen und float getAccountValue(void) // Kontostand abfragen implementiert.
Nun habe ich die Headerdatei cBankAccount.hpp der die Klasse definiert ist in die Datei cBankAccount.cpp includiert.
In der Datei cBankAccount.cpp werden sämtlichle Methoden inclusive Konstruktor und Destruktor mit Leben gefüllt.
Die Datei cBankAccount.cpp habe ich in die main.cpp includiert.
Hier mal mein Code ich wäre euch echt Dankbar wenn mir jemand Helfen könnte.
cBankAccount.cpp
Code: Alles auswählen
#include "cBankAccount.hpp"
void cBankAccount::setMoney(float value)
{
cBankAccount::fMoney += value;
}
float cBankAccount::getMoney(float value)
{
return (cBankAccount::fMoney -= value);
}
float cBankAccount::getAccountValue(void)
{
return (cBankAccount::fMoney);
}
cBankAccount::cBankAccount()
{
cBankAccount::fMoney = 0;
}
cBankAccount::~cBankAccount()
{
cBankAccount::fMoney = 0;
}
cBankAccount.hpp
Code: Alles auswählen
class cBankAccount
{
private:
float fMoney;
public:
void setMoney(float value);
float getMoney(float value);
float getAccountValue(void);
cBankAccount();
~cBankAccount();
};
//main.cpp
Code: Alles auswählen
#include <iostream>
#include "cBankAccount.cpp"
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
cBankAccount.cpp|4|multiple definition of `cBankAccount::setMoney(float)'|
cBankAccount\cBankAccount.cpp|4|first defined here|
Diese Fehlermeldung kommt für jede Methode.
Ich bin für jede Hilfe dankbar
Gizmo