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:
Anonymous2007-01-15 20:28
the insertion operator takes shit and pumps it into a stream. it doesn't really understand what you mean by "the formatted string" because it's a stream operator. it only knows the value you've passed it.
so, for example:
a << "hello " << "world" << someVariable << endl;
would call the stream operator four times, the first time it would be puming "hello " into a, the second time it would be pumping "world", the third time it would be pumping someVariable, and the fourth time it would be pumping endl. each occurrence is distinct from the rest.
so, at best, you'd be able to call print("hello "), print("world") and so on.
Name:
Anonymous2007-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?
Name:
Anonymous2007-01-15 21:09
>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?
yeah, that's doable, but seems pretty ugly. why not just make print() take a stream instead of a string?
Name:
Anonymous2007-01-15 21:32
>>3
|so, how would I be able to have something like printf as a class method?
oh, I didn't know it was possible to use ellipses inside class methods. i recall one time trying to do it but got compiler errors. i tried it in vc8 and it works. i cant believe it.
Name:
Anonymous2009-01-14 14:30
GTFO
Name:
Anonymous2009-03-06 7:14
A=wsh createobject msxml2 xml while 1 a gentle introduction to programming a modern shmup with 3D models 3D backgrounds scripting language and a graphics library For now I see properly implemented static typing as a HUGE improvement over any kind of project as long as we can complete it in the alloted time What are we going to spam them to edit and kill all toolbars Add some simple formulas and poof you have your application Serious software companies work this way You can either.