I grouped several lines of messages into a named (non-anonymous) namespace in a .cpp file to output class processing, as shown in the code below:
namespace Messages
{
static const std::string AppTitle = "The Widgetizer - Serving all your Widget needs";
static const std::string SuccessMsg = "Great success! Widgets for all! ";
static const std::string FailMsg = "No widgets for you!";
};
void Display::printTitle()
{
out << Messages::AppTitle << std::endl;
}
void Display::printSuccessMsg()
{
out << Messages::SuccessMsg << std::endl;
}
void Display::printFailMsg()
{
out << Messages::FailMsg << std::endl;
}
My logic is that in this way they are all in one central place, under the namespace with a meaningful and self-documenting name, and they are not exposed to the client code (as it would be if I put the namespace in the .h file) .
Is this good practice at all or are there pitfalls that I don't see?
Is a static keyword necessary if they are in the namespace for a file area like this?
++, , ? const?
, , , , , , , , , , - ?