I am trying to overload the operator << to display contents on the object, but I need it in a few different classes so I make the operator << and showStatus() function templates.
IDE shows the following error:
Undefined symbol: operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, Mege const&)
Not sure about what it is.
I delete some unrelated code so this question will not be too much code to be posted. Let me know if more details are needed.
Help would be appreciated.
class Hero : public Entity{
private:
public:
template <class T>
void showStatus(T){}
};
#include "Hero.hpp"
#include <math.h>
Hero::Hero(){
}
// overloading << for showing different hero's status
template <class T>
std::ostream &operator << (std::ostream &strm, const T &hero){
strm << hero.getName() << endl
<< "-------------------------------"
<< "Level: " << right << setw(4) << hero.getLevel() << endl
<< "EXP: " << hero.getExp() << " / " << hero.getExpNext() << endl
<< "HP: " << hero.getCurrHp() << " / " << hero.getMaxHp() << endl
<< "Damage: " << hero.getMinDamage() << " ~ " <<hero.getMaxDamage() << endl
<< "-------------------------------"
<< "Strength: " << hero.getStrength() << endl
<< "Intelligence: "<< hero.getInterlligence() << endl
<< "Stamina: " << hero.getStamina() << endl
<< "Speed: " << hero.getSpeed() << endl
<< "-------------------------------" << endl << endl;
return strm;
}
#include <stdio.h>
#include <iostream>
#include "Hero.hpp"
class Mege : public Hero{
private:
public:
Mege();
~Mege();
// function
friend std::ostream &operator << (std::ostream &strm, const Mege &hero);
void updateStatus() override;
void showStatus(Mege) ;
// setter
// getter
};
#include "Mege.hpp"
#include <math.h>
std::ostream &operator << (std::ostream &strm, const Mege &mege);
void Mege::showStatus(Mege mege){
cout << mege;
}