When I compile I get this error message for istream
error: no match for 'operator>>' in 'in >> ((Rock*)this)->Rock::myName'
I did not include the program with main because I have not used it yet.
#ifndef ROCK_H
#define ROCK_H
#include<iostream>
using namespace std;
enum RockName {BASALT, DOLOMITE, GRANITE, GYPSUM, LIMESTONE, MARBLE, OBSIDIAN,
QUARZITE, SANDSTONE, SHALE, ROCK_OVERFLOW};
class Rock
{
public:
Rock();
Rock(RockName rockName);
void display(ostream & out) const;
void read(istream & in);
private:
RockName myName;
};
ostream & operator <<(ostream & out, const Rock &t);
istream & operator >>(istream & in, Rock &t);
#endif
#include <iostream>
using namespace std;
#include "Rock.h"
Rock::Rock():myName(BASALT)
{
}
Rock::Rock(RockName rockName)
{
myName= rockName;
}
void Rock::display(ostream & out) const
{
out<<myName;
}
void Rock::read(istream &in)
{
in>>myName;//this is where I am getting the error
}
ostream & operator<<(ostream & out, const Rock & t)
{
t.display(out);
return out;
}
istream & operator>>(istream & in, Rock & t)
{
t.read(in);
return in;
}