c++ problem z klasą

0

Witam
No i pojawił się kolejny problem.
Otóż mam już prawie gotowy program tylko chcę go napisać na klasach.
Niby zrobiłem jedną klasę ale niestety wywala mi taki oto błąd.
http://img651.imageshack.us/img651/5126/29731491.png
Mam nadzieję, że będzie ktoś mi w stanie pomóc.

A oto moje pliki z klasą.

banknoty.cpp

 #include "banknoty.h"
#include <iostream>
#include <fstream>
#include <map>
#include <limits>
#include <vector>
using namespace std; 
      void banknoty::alg(int, map<int, int>&)
      {
		  while(true)
		  {
          ifstream iFile("./dane/banknoty.txt");
          int a, b;
          map<int, int>mapa;
          while(iFile >> a >>b )
          mapa.insert(pair<int, int>(a, b));  
          map<int, int>::iterator it = mapa.begin();
          for(;it != mapa.end(); ++it)
          cout << (*it).first << " " << (*it).second << "\n";     
          int n;
          cout << "ile wyplacic? : ";
          cin >> n;    
          alg(n, mapa); 
          it = mapa.begin();    
          ofstream oFile("./dane/banknoty.txt");
          for(;it != mapa.end(); ++it)
          oFile << (*it).first << " " << (*it).second<<"\n";
          oFile.close();
          system("pause");
		  }
	  }

banknoty.h

 #pragma once
#include <map>
#include <limits>
#include <vector>
using namespace std; 
class banknoty
{
public:
	     void banknoty::alg( int v, map<int, int> &m )
      {
          map<int, int>::reverse_iterator it = m.rbegin();
          for(; it != m.rend(); ++it)
          {
          while((*it).first <= v && (*it).second > 0)
              {
               v -= (*it).first;
               (*it).second--; 

            }
         }
      } 
};
1

nie rozumiem yyy... masz chyba dwie identyczne deklaracje funkcji 'alg', tzn i w pliku banknoty.c i w pliku banknoty.h (ta sama nazwa, te same argumenty).
Jeśli byś je chciał choćby przeładować to muszą się różnić argumentami.. Przeanalizuj swój kod jeszcze raz ;)

1
class banknoty
{
public:
             void banknoty::alg( int v, map<int, int> &m )
      {
          map<int, int>::reverse_iterator it = m.rbegin();
          for(; it != m.rend(); ++it)
          {
          while((*it).first <= v && (*it).second > 0)
              {
               v -= (*it).first;
               (*it).second--; 
 
            }
         }
      } 
};

void banknoty::alg(int, map<int, int>&)
      {
                  while(true)
                  {
          ifstream iFile("./dane/banknoty.txt");
          int a, b;
          map<int, int>mapa;
          while(iFile >> a >>b )
          mapa.insert(pair<int, int>(a, b));  
          map<int, int>::iterator it = mapa.begin();
          for(;it != mapa.end(); ++it)
          cout << (*it).first << " " << (*it).second << "\n";     
          int n;
          cout << "ile wyplacic? : ";
          cin >> n;    
          alg(n, mapa); 
          it = mapa.begin();    
          ofstream oFile("./dane/banknoty.txt");
          for(;it != mapa.end(); ++it)
          oFile << (*it).first << " " << (*it).second<<"\n";
          oFile.close();
          system("pause");
                  }
          }

więc tak:

  1. Masz bubla wewnątrz klasy bo definiujesz metodę alg i robisz to przy pomocy operatora zasięgu "::" - źle.
  2. Tą samą metodę redefiniujesz poza klasą - zdecyduj się wewnątrz, czy poza.
  3. Sformatuj ten kod jakoś dobrze bo brzydko wygląda :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1