error: no match for 'operator<<'

Hi, I need to make a text-base video game for collage. There has to be a class character but I am having an error message:

Class_Character.h:36: error: no match for 'operator<<' in 'os << char1.character::give_race'


this is my header file for the class character:

#ifndef CHARACTER
#define CHARACTER
#include <iostream>
#include <string>

class character
{
friend std::ostream& operator<<(std::ostream&, character);

public:
std::string give_race();
int give_STR();
int give_CON();
int give_DEX();
int give_CHA();
void set_race(string);
void set_properties ();
void save_race();



private:
std::string race;
int STR;
int CON;
int DEX;
int CHA;
int throw_dices_for_properties();



};

inline std::ostream& operator<<(std::ostream& os, character char1) {
return os << char1.give_race;
}


#endif


If you guys know what is wrong with it plz chare :d!
Hi Toongun,

In your character class, you need to declare the header of ofstream as a friend function inside your character header file. e.g.:

friend std::ostream& operator<<(std::ostream& os, const character &rhs);

place the function after void save_race() and give it a shot.
Last edited on
The only problem I see is that you are not trying to print a string, but a pointer to a function that has void parameters and returns std::string. Change return os << char1.give_race; into return os << char1.give_race();
@Kyron: thx man, this was the problem, stupid of me to not see this one :s.
But thx again man!
Topic archived. No new replies allowed.