No Match for operator>>

I need to implement istream outside of class and without friend. I keep getting "no match for operator>>" error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Dot
{
public:
  void PutName (const char*); 
  void PutBarCode (uint32_t);   
  void PutCost (float);
  const char* ObtainName ()const;         
  uint32_t ObtainBarCode () const;        
  float ObtainCost () const;    

private:

char* name_;
uinit32_t code_;
float cost;

};

std::istream& operator>> (std::istream& is, Dot& d)
{
 is >> d.ObtainName() >> d.ObtainBarCode() >> d.ObtainCost();
return is;
} 
Where are your class function implementations?

Also you probably will need to call your member functions and "assign" the values to the class variables.

1
2
3
4
5
6
7
8
9
std::istream& operator>> (std::istream& is, Dot& d)
{
     char name[100];
     is >> name;
     PutName(name);
... etc.

    return is;
} 


Oh, and where are you allocating memory for that pointer? You really should consider using a std::string instead of the error prone C-strings.

Last edited on
I figured it out. I included a print function in my class and called it in my overload function. I was trying to implement without having to use friend nor add operator function to my class. Thanks for the help though.
Registered users can post here. Sign in or register to post.