Za czołem poznawać klasy, napisałem oto taki programik.
//main.cpp
#include <iostream>
#include <cstdlib>
#include "classdeclaration.h"
#include "metody.cpp"
#include "prototype.h"
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(void)
{
rachunek konto1;
int wybor;
menu();
std::cin >> wybor;
while(1)
{
switch(wybor)
{
case 1:
wplata(konto1);
break;
case 2:
wyplata(konto1);
break;
case 3:
konto1.pokaz();
break;
case 4:
exit(EXIT_SUCCES);
default:
std::cout << "Zle" << std::endl
break;
}
}
return 0;
}
//classdeclaration.h
#ifndef RACHUNEK_C
#define RACHUNEK_C
#include <string>
class rachunek
{
private:
std::string nazwisko;
int saldo;
unsigned int numer_konta;
public:
rachunek();
rachunek(std::string nazwa, int kwota, unsigned int nrKonta);
void pokaz();
void wplata(int kwota);
void wyplata(int kwota);
~rachunek();
}
#endif
//funkcje.cpp
#include <iostream>
#include "classdeclaration.h"
void menu(void)
{
std::cout << "1.Wplata" << std::endl
<< "2.Wyplata" << std::endl
<< "3.Pokaz" << std::endl
<< "4.Exit" << std::endl;
}
void wplata(rachunek & x)
{
unsigned int kwota;
std::cout << "Ile hcesz wplacic?: ";
std::cin >> kwota;
x.wplata(kwota);
}
void wyplata(rachunek & x)
{
unsigned int kwota;
std::cout << "Ile hcesz wyplacic?: ";
std::cin >> kwota;
x.wyplata(kwota);
}
//prototype.h
#include "classdeclaration.h"
void menu(void);
void wplata(rachunek & x);
void wyplata(rachunek & x);
//metody.cpp
rachunek::rachunek(std::string nazwa, int kwota, unsigned int nrKonta)
{
nazwisko = nazwa;
saldo = kwota;
numer_konta = nrKonta;
}
void rachunek::rachunek::pokaz()
{
std::cout << "Nazwisko: " << nazwisko << std::endl
<< "Nr Konta: " << numer_konta << std::endl
<< "Saldo : " << saldo << std::endl;
}
void rachunek::wplata(int kwota)
{
saldo += kwota;
}
void rachunek::wyplata(int kwota)
{
saldo -= kwota;
}
program wykrywa mi taki błąd w pliku class declaration.h
[Error] new types may not be defined in a return type
(perhaps a semicolon is missing after the definition of 'rachunek')
jest linie 7 kolumna 1 czyli klamerka pod class rachunek
pisałem to według książki, mimo to się nie kompiluje i nie wiem dlaczego