The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 11-20-2007
fpmurphy fpmurphy is offline
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,125
Try the following:

Code:
#include <iostream>

using namespace std;

class Line; // Forward Declaration for friend

class Point
{
  friend ostream& operator<< ( ostream& , const Line&);
  friend istream& operator>> ( istream& , Line&);

 private:
  int x,y;
};

class Line : public Point
{
  friend ostream& operator<< ( ostream& , const Line&);
  friend istream& operator>> ( istream& , Line&);

 private:
  int color;

 public :
   void draw () { cout<< "Drawing a Line" << endl; }
};

inline
ostream& operator<< ( ostream &os , const Line &out )
{
  os << "Line: [" << out.x << "," << out.y << " ," << out.color << " ]" << endl;
  return os;
}

inline
istream& operator>> ( istream &is , Line &in )
{
  cout << "Line x , y , color info: " << endl;
  is >> in.x >> in.y >> in.color;
  return is;
}

int
main(int argc, char *argv)
{
   Line new_line;

   cin >> new_line;
   cout << new_line;

   return(0);
}
Reply With Quote