output:
#include
#include
#include
using namespace std;
class some
{
protected:
string id;
public:
some (string aid){ id = aid; }
friend ostream & operator (ostream &, some &);
};
ostream & operator << (ostream & fout, some & asome)
{ fout << "Class some: " << id << endl;}
class someother : public some
{
public:
someother (string aid) : some (aid){}
friend ostream & operator << (ostream &, someother &);
};
ostream & operator << (ostream & fout, someother & asome)
{ fout << "Class someother: " << id << endl;}
int main ()
{
some A ("A");
some B ("B");
some * C = new someother ("C");
cout << style="color: rgb(0, 0, 0);">;
cout << B;
cout << (*C);
delete C;
return 0;
}
Class some: A
Class some: B
Class some: C
As you can see above, the objective was to call the operator <<
#include
#include
#include
class some
{
protected:
string id;
public:
some (string aid){ id = aid; }
friend ostream & operator << (ostream &, some &); virtual ostream & print (ostream & fout)
{
fout "Class some: " <<>return fout;
}
};
class someother : public some
{
public:
someother (string aid) : some (aid){}
virtual ostream & print (ostream & fout)
{
fout << "Class someother: " <<>return fout;
}
};
int main ()
{
some A ("A");
some B ("B");
some * C = new someother ("C");
A.print (cout);
B.print (cout);
(*C)print (cout);
delete C;
return 0;
}
No comments:
Post a Comment