I keep getting this error for the Pet read function: no match for 'operator>>' in 'fin >> ((Pet*)this)->Pet::age' whenever trying to compile the class. I have not implemented anything into main, but I am trying to figure out how to fix this problem so I can go on. Any help or insight is appreciated.

#include <iostream>

using namespace std;

    class Pet
{
     protected:
        string name;
        double age;
     public: 
        Pet();
        Pet(string name, double age);
        void setName( string name);
        void setAge (double age);  
        string getName ();
        double getAge ();
        void print(ostream &out = cout);
        void read(ifstream &fin);
        ~Pet();                  
};   



Pet::Pet(string namevalue, double agevalue)
{
               name=namevalue;
               age=agevalue;
}

Pet::Pet()
{
         name="";
         age=0;
}

void Pet::setName (string input)
{
     name=input;
}


void Pet::setAge (double input)
{
     age=input;
}

string Pet::getName()
{
       return name;
}

double Pet::getAge()
{
       return age;
}

void Pet::print(ostream &out = cout) //this is where the error exists
{
     cout << name << " " << age << endl;
}

void Pet::read(ifstream &fin) //this is where the error exists
{
     fin >> age >> name;
}

cout << name << " " << age << endl;

in that line cout should probably be changed to out.
________________________________________
>> I keep getting this error for the Pet read function: no match for 'operator>>' in 'fin >>

You need to include the fstream header file if you want to use an ifstream object in your program. Do that and recompile. However, to make it more generic, I'd change ifstream to just istream.

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.