I've got this header and cpp.And I would like to insert this operator overloading to this .h and .cpp file. but I always got errors.

Operator OVERLOADING :

istream& operator>>(istream& in, Focista& jatekos) {
        cout << "Add meg a focista tulajdonsagait. " << endl;
        cout << "Nev: " << endl;       in >>   jatekos.nev ;
        cout << "Csapat: "  << endl;   in >>  jatekos.csapat;
        cout << "kor: "    << endl;    in >>  jatekos.kor ;
        cout << "suly: "   << endl;    in >>  jatekos.suly;
        cout << "Poszt "   << endl;    in >>   jatekos.poszt ;
        cout << "Fejeles: " << endl;   in >>   jatekos.fejeles;
        cout << "Gyorsasag: " << endl; in >>  jatekos.gyorsasag;
        cout << "Cselezes: "  << endl; in >>  jatekos.cselezes;
        cout << "Passz: "     << endl; in >>   jatekos.passz;
        return in;
        }

HEADER :

#include <string>
#include <iostream>
#include "Man.h"
#ifndef  FOCISTA_H
#define  FOCISTA_H
using namespace std;
using std::string;

namespace player{
      class Focista : public ferfi::Man 
      {
       public:   
               string  poszt;
          int fejeles;
          int gyorsasag;
          int cselezes;
          int suly;
          int passz;
              
        //default constructor, meghívja a Man() default kontruktorát,

        Focista();
        //overloaded constructor
        Focista(string nev, int kor, string csapat,  string poszt,  int fejeles,
                 int gyorsasag,  int cselezes,  int suly, int passz)  ;      //destructor
        ~Focista();
         //getters
         string getPoszt()const;
         int getFejeles()const;
         int getGyorsasag()const;
         int getCselezes() const;
         int getSuly() const;
         int getPassz() const;
         //setters
         void setPoszt(string poszt);
         void setFejeles(int fejeles);
         void setGyorsasag(int gyorsasag);
         void setCselezes(int cselezes) ;
         void setSuly(int suly) ;
         void setPassz(int passz) ;
         //+method for example ooverloading

      };//end of class
}//end of namespace
#endif

And i've got this .cpp with the extends of method.

CPP:

#include "Focista.h"
#include <iostream>
//constructor
using namespace std;
player::Focista::Focista()
{
           this->poszt = "MDF";
           this->fejeles = 10;
           this->gyorsasag = 10;
           this->cselezes = 10;
           this->suly = 85;
           this->passz = 8;                     
          
}
        //overloaded constructor
        player::Focista::Focista(const string nev, const int kor, const string csapat, const string poszt, const int fejeles,
                const int gyorsasag, const int cselezes, const int suly, const int passz)
        {
           
           this->poszt = poszt;
           this->fejeles = fejeles;
           this->gyorsasag = gyorsasag;
           this->cselezes = cselezes;
           this->suly = suly;
           this->passz = passz;
        }
        player::Focista::~Focista(){}
       //setters
       void player::Focista::setCselezes(int cselezes){this -> cselezes =cselezes;}
       void player::Focista::setFejeles(int fejeles) {this -> fejeles = fejeles;}
       void player::Focista::setGyorsasag(int gyorsasag) { this -> gyorsasag = gyorsasag;}
       void player::Focista::setPassz(int passz) {this -> passz = passz ;}
       void player::Focista::setSuly(int suly) {this -> suly = suly;}
       void player::Focista::setPoszt(string poszt) {this -> poszt = poszt ;}
       //getters
       int player::Focista::getCselezes()const {return cselezes;}
       int player::Focista::getFejeles() const {return fejeles;}
       int player::Focista::getGyorsasag() const { return gyorsasag;}
       int player::Focista::getPassz() const {return passz; }
       int player::Focista::getSuly() const { return passz;}
       string player::Focista::getPoszt() const {return poszt;};
       //+method

Somebody have any idea?

Recommended Answers

All 2 Replies

What are the errors? When do you get them (during compilation or when you run the program)?

to cpp:

istream& player::operator>>(istream& in, player::Focista& jatekos)
		{
			cout << "Add meg a focista tulajdonsagait. " << endl;
			string name;
			string csapat;
			string  poszt;
			int kor;
	    	int fejeles;
		    int gyorsasag;
	    	int cselezes;
	      	int suly;
	       	int passz;
			cout << "Nev: " << endl;       in >>  name;      jatekos.setName(name) ;
			cout << "Csapat: "  << endl;   in >>  csapat;    jatekos.setTeam(csapat);
			cout << "kor: "    << endl;    in >>  kor;       jatekos.setKor(kor) ;
			cout << "suly: "   << endl;    in >>  suly;      jatekos.setSuly(suly);
			cout << "Poszt "   << endl;    in >>  poszt;     jatekos.setPoszt(poszt) ;
			cout << "Fejeles: " << endl;   in >>  fejeles;   jatekos.setFejeles(fejeles);
			cout << "Gyorsasag: " << endl; in >>  gyorsasag; jatekos.setGyorsasag(gyorsasag);
			cout << "Cselezes: "  << endl; in >>  cselezes;  jatekos.setCselezes(cselezes);
			cout << "Passz: "     << endl; in >>  passz;     jatekos.setPassz(passz); 

			return in;
		}

to header :

friend istream& operator>>(istream& in, Focista& jatekos) ;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.