   #define question
  I am trying to load a default port number from my .ini file in my server folder, I was wondering if I could use #define to do it?how I get my config information is like this struct_cast<int>(server_config["port"]);so what I was wondering is if I can do this..#define DEFAULT_PORT struct_cast<int>(server_config["port"]);or would that not work?? thanks in advance :D   
  It probably wouldn't work how you want it to work with the ; in the define and it'll only work in places where server_config and struct_cast are defined. But if you just want a brute force text replacement, a #define will do it. It's a bad idea, but it'll work.   ;  Well for one you probably mean static_cast<..> right? This is C++?   ;  It might work (the trailing semicolon is a problem), but what benefit does it have? You will probably only be reading the value in one or two places in your program, but you have almost written more code to do so. And the code now obfuscates what is going on.Using the preprocessor is usually best avoided. It doesn't understand the C++ language, so it can cause issues. For instance, your current version would allow me to write code like this:int port = DEFAULT_PORT // no semicolonAnd it would compile fine!Many features of C++ were initially added to avoid using the preprocessor. In this case, one might use a function. inline int defaultPort(const Config &config){   return struct_cast<int>(config["port"]);}Again though, you have to ask yourself what advantage you are getting with such a scheme.Another would be to give the Config type a template member, to hide the "struct_cast" (whatever that is, not a lover of boost::lexical_cast?):class Config{    template<class T>    T get( const std::string &name ) const    {    return struct_cast<T>(/* ... */);    }};The calling code becomes:int port = config.get<int>("port");Which is relatively neat.   ;  Ok, so I could use int instead then? Reason I am doing it this way is so I can easly change PORT, and BUFFER Defaults, without having to change the code....so if I was to use int it would be likeint DEFAULT_PORT = struct_cast<int>...All my Config, an stuff is declared in config.hpp/.cpp also in util.hpp/.cppanyways thanks for all the reply's....hope to get more so I can figure it out :D   ;  I think a good rule of thumb is to never, ever use #define to write actual code in C++.  Use it for configuring code - and the odd macro if you must, where a function won't do.  For example, use it to compile different sections of code depending on the current build configuration (like release/debug).  C++ almost always can write code cleaner, safer and more readable, with built-in language features.   ;  Well I figured out how to get it to do it so it's a little better..int DefaultPort;DefaultPort = static_cast<int> etc etcseems to work for now so I am going to keep on using it :D   