Declaring constant references
This is a continuation of the problem here.
I just defined my own ctype
Code:
class AnsiCType : public std::ctype<char>
{
public:
AnsiCType(std::size_t refs = 0);
private:
mask ansi_table[table_size];
};
Now, I've run into a problem that I have an idea of how to solve, I just don't want to solve it that way.
I'm trying to declare a ctype so that it can be defined based on the command line argument, but if there is no locale argument from the command line, it will default to AnsiCType. This is the outline that I have, and, obviously, it won't work.
Code:
const std::ctype<char>& ct; //obviously there will be an error here because it's not initialized
if(there are command line arguments declaring a locale)
std::locale loc(command line locale);
ct = std::use_facet<std::ctype<char> >(loc); //another no no
else
{
AnsiCType act;
ct = act; //another big no no, so how do I get around this?
}
I need to have my ctype variable to be accessible within the scope of "main" because I'm passing it on as an argument to another function.
The obvious solution is
Code:
if(there are command line arguments declaring a locale)
std::locale loc(command line locale);
const std::ctype<char>& ct = std::use_facet<std::ctype<char> >(loc);
call_my_function(ct);
else
{
AnsiCType act;
call_my_function(act)
There are several reasons I don't want to do this, the most important being that I don't want to have to handle command line arguments twice (once before, for reading in data files).
Any help would be appreciated.