There is something that I would really enjoy in C++ if it is possible.
This works for a single data type. However, what would I do if I had something like this?Code:class Console { public: template <class T> static void WriteLine(T text) { std::cout << text << std::endl; } template <class T> static void Write(T text) { std::cout << text; } };
float price = 5.25f;
Console::WriteLine("The price is " + price + "."); // outputs The price is 5.25.
I would assume I need to overload the operator '+' somehow within this and concatenate everything together into a final string. I know C# isn't C++, and visa-versa, but for some programming tasks this would save some work. I learned not to ever use std::cout directly as much as Java's System.out.println(). Instead they should be in wrappers so we can change output in one method instead of changing it throughout the entire project. This also allows us to output to a GUI, file, or whatever later on if we ever wished. So something above would be ideal and better abstracted, although I'm not sure how to go about something like it.