-
Loading Different Headers Variable based
if i have two different headers one MyHeaderFr.h and the other MyHeaderUS.h and i have a string var that hold "US" or "FR" how do i load the header files accordingly?
Thank You,
-
You have string variable with same name in both headers?If yes, the you can enclose them inside a namespace and use accordingly.
-
sorry if my original post was not clear but i want to load only one of the headers. So i load MyHeaderFR.h or MyHeaderUS.h.
-
I really have lost you completely. What exactly are you trying to do and what is the problem you're facing? Can't you simply #include the header that you need?
Danny Kalev
-
I sorry let me try to explain it better.
I have for example i have a const string in two different headers. One is US.h the other FR.h
Code:
---US.h---
const string welcome = "HI";
---FR.h---
const string welcome = "Bonjour";
i my main code i have some thing like this
Code:
string lang = "US";
depending on the value of lang i want to loader either the US.h or FR.h
-
just use a #define combined with #if like
Code:
#include "language_selector_header.hpp"
#if defined USE_FRENCH_HEADER
#include "FR.h"
#elif defined USE_USE_HEADER
#include "US.h"
#elif
/// ...
#endif
/// '''
and un the file language_selector_header.hpp define a variable for the language you would like to use
like
Code:
#define USE_MANDARIN_LANGUAGE
or something more clever.
Insome compilers you can even pass a preprocessor variable like that on the command line...
Cheers,
D
DKyb-------------------------------
Life is a short warm moment -
Death is the long cold rest.
Pink Floyd
-------------------------------
-
Are you looking to implement this at "run time" or at "compile time"?
-
You can't use a string object, which is a runtime notion (as are all objects) to make a decision that takes place conceptually before compilation time! When the preprocessor evaluates the #ifdef and #include expressions, the notion of strings and objects is completely inexistent yet. Think of the preprcessor as a clever text editor, not as anything that's even close to a C++ compiler.
So you need to use another macro, not a string, in order to determine during the preprocessing stage which header should be #included.
I also have to warn you that embedding string objects in a header file is a bad idea. The problem is that the header can be #included multiple times in each translation unit, and the result is multiple copies of string objects. The linker rarely has the cleverness to collapse all these strings into a single instance. A much better solution is to #define a macro in the header file and use that macro at runtime to assign a value to a shared string. Alternatively, use environment variables to determine the locale at runtime, and the load the appropriate strings from a file.
Danny Kalev
-
by doing this
Code:
#include "language_selector_header.hpp"
#if defined USE_FRENCH_HEADER
#include "FR.h"
#elif defined USE_USE_HEADER
#include "US.h"
#elif
/// ...
#endif
/// '''
seem like i have to hard code in what language to use. I was hoping to uses a string/char variable that could be assigned after reading data from a file.
-
Then use a string table stored in a file, and load that string table into the program at runtime. You can do it more elegantly with locales, if you have some experience with this library.
Danny Kalev
Similar Threads
-
By edburdo in forum ASP.NET
Replies: 3
Last Post: 07-13-2006, 10:43 PM
-
By raj74 in forum ASP.NET
Replies: 2
Last Post: 04-13-2003, 05:05 PM
-
By Manoj Shah in forum Web
Replies: 1
Last Post: 07-02-2001, 10:50 AM
-
By Patrick Buchanan in forum ASP.NET
Replies: 3
Last Post: 11-29-2000, 12:06 PM
-
By Nikhil in forum ASP.NET
Replies: 2
Last Post: 05-11-2000, 03:18 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks