Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ help

Name: Anonymous 2007-01-15 20:15

hi /prog/

suppose I had a class

class ABC
{
public:
    ABC() {}
    void print(std::string s) { // do something with s }
};

and in my program I wanted to do:

ABC a;
a << "hello " << "world" << someVariable << endl;
but I wanted the << operator to call print, passing the formatted string as s.
how would i do this?



Name: Anonymous 2007-01-15 20:34

ah, i see. so, how would I be able to have something like printf as a class method? ie. formatting a string with variables and passing it to the method, all within in the paramater list.

also, okay if i overloaded operator <<, could i then just have everything saved to some string, then when endl is reached, i call print with the formatted string?

sort of like:
a << "hello"; // m_format += hello;
a << "world"; // m_format += world;
a<<endl; // Print(m_format);

would this work or am i horribly mistaken?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List