Is it Safe to Use this in Code?
Is it safe to have a method in a class to be named cout? I was wondering if I should change it, but it is easier to just use .cout after the instance of the class..
It's legal C++ and your compiler won't complain about it, but if you think about it, cout is a pretty funky name to begin with. Member functions should usually have nice descriptive names, which usually tend to be verb like.
Well keep in mind C++ is case sensitive so why not go with something like cOut?
Then again SiCrane is right descriptive names are good.
[Edited by - Gor435 on August 15, 2005 10:42:15 PM]
Then again SiCrane is right descriptive names are good.
[Edited by - Gor435 on August 15, 2005 10:42:15 PM]
Quote:Original post by orcfan32
Ok then, I'll change it to .PrintVal for "Print Value".
Quote:Well keep in mind C++ is case sensitive so why not go with something like cOut?
Quote:Original post by pinacoladaQuote:Original post by orcfan32
Ok then, I'll change it to .PrintVal for "Print Value".Quote:Well keep in mind C++ is case sensitive so why not go with something like cOut?
Was just offering an option. [razz]
I even said "descriptive names are good."
Quote:Original post by pinacolada
The smiley means the code is happy =D . In other words, "PrintVal" is a good way to go.
And I can't help but to wonder why PrintValue wouldn't be a good name for a function that prints the value...
the extra 'eu' won't kill you and if you find yourself repeatedly typing it so that two more keystrokes would become a burden then you probably need to rethink what you're doing...
Just my oppinion, also I generally disslike the idea of having "print" functions in classes since I personally have a hard time associating printing with a core responsibility of the class. Classes should have one well defined responsibility, schizophrenia really is a bad thing, even though it can sometimes be fun to mock... But we're not that kind of people now are we?
Quote:Original post by DigitalDelusion
Just my oppinion, also I generally disslike the idea of having "print" functions in classes since I personally have a hard time associating printing with a core responsibility of the class. Classes should have one well defined responsibility, schizophrenia really is a bad thing, even though it can sometimes be fun to mock... But we're not that kind of people now are we?
Hmm. Instead of friending an insertion operator, I tend to write a public stream() member function that an insertion operator calls. Like so:
class Foo { public: template <typename Elem, class Traits> void stream_formatted(std::basic_ostream<Elem, Traits> & os) const { os << /* stuff */ } private: // whatever};template <typename Elem, class Traits>std::basic_ostream<Elem, Traits> & operator<<(std::basic_ostream<Elem, Traits> & lhs, const Foo & rhs) { rhs.stream_formatted(lhs); return lhs;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement