Is it Safe to Use this in Code?

Started by
9 comments, last by DigitalDelusion 18 years, 8 months ago
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..
The best thing to do is just choose whatever you think you'd prefer, and go for it. -Promit
Advertisement
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.
Ok then, I'll change it to .PrintVal for "Print Value".
The best thing to do is just choose whatever you think you'd prefer, and go for it. -Promit
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]
Gor435 - My Journal - MySpace - Facebook
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?
Lol, what's the smilies for?
The best thing to do is just choose whatever you think you'd prefer, and go for it. -Promit
The smiley means the code is happy =D . In other words, "PrintVal" is a good way to go.
Quote:Original post by pinacolada
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?


Was just offering an option. [razz]

I even said "descriptive names are good."
Gor435 - My Journal - MySpace - Facebook
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?
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
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