Hi,
One of the really nice features of c++ IMHO are iostreams. Just define the << operator and voila, you can outut you object to the console or files etc.
The problem is what if I wanted to replace cout in the first place? What if I wanted to do say, coutGL << "Lalalala" << endlGL; to output to an OpenGL scene, how could that be accomplished?
This is not a GL question... I''m interested in overloading?/ inhereting from? cout.
Thanks,
OberonZ
---
PAGE FAULT: Please insert "Swap File, Disk 2"
and press any key to continue.
Replacing cout
---
PAGE FAULT: Please insert "Swap File, Disk 2"
and press any key to continue.
PAGE FAULT: Please insert "Swap File, Disk 2"
and press any key to continue.
Im not sure about the overloading inheriting part of cout, but you could try this. Just make a class that has your output routines and contains an operaotor overload of << and has what you want to do with it through the function implementation.
class foo
{
private:
...
public:
friend ostream& operator<<(whatever params you need)
};
Then code the function body in the .cpp file for your class. Since it is a friend function, when you add the body omit the foo:: part of it. The just instantiate an object of your class and when ever you use the << on a member of that class your overloaded << will get called.
Mike Barela
mbarela@earthlink.net
class foo
{
private:
...
public:
friend ostream& operator<<(whatever params you need)
};
Then code the function body in the .cpp file for your class. Since it is a friend function, when you add the body omit the foo:: part of it. The just instantiate an object of your class and when ever you use the << on a member of that class your overloaded << will get called.
Mike Barela
mbarela@earthlink.net
Mike BarelaMikeB@yaya.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement