Jump to content
  • Advertisement
Sign in to follow this  
orcfan32

Is it Safe to Use this in Code?

This topic is 4845 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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..

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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."

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!