<bl**********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Here A is an instantiation of class Matrix. This means whenever user
writes
Matrix<float> A=rand<float>(3,2);//create a float matrix of size 3x2
//and fills it up w/ random value
cout<<A;
the following will be printed
A
3
2
.1 .9
.2 .4
.5 .6
If all you need is any identification on the output, you can use the address
of the object in operator<<:
#include <iostream>
using namespace std;
class Foo
{
friend ostream & operator<< (ostream &, Foo const &);
int i_;
public:
explicit Foo(int i)
:
i_(i)
{}
};
ostream & operator<< (ostream & os, Foo const & object)
{
return os << "Foo at " << &object << ":\n"
<< object.i_;
}
int main()
{
Foo object(42);
cout << object << '\n';
}
Ali