Overload Operator

I need help overloading operator for the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)
{
 ?
}

Last edited on
Put this inside your class.

 
    friend std::istream& operator>>(std::istream&, Dot&);
Is there a way of doing this without putting it inside my class and without using friend?
Yes. You already had it. I mostly see it as a friend, but you can do an out of class definition as well.
https://stackoverflow.com/questions/19550030/how-to-overload-operator-without-friend-function
Every time I included outside the class without friend, I get a "no match for operator" error.
Registered users can post here. Sign in or register to post.