Re: cannot recognize vector as a vector, please help
From: Malte Starostik (malte_at_starostik.de)
Date: 03/29/05
- Next message: Julián Albo: "Re: Convert from std::vector<double> to std::vector<int>"
- Previous message: Zak: "Re: Exe will not start"
- In reply to: John Guo: "Re: cannot recognize vector as a vector, please help"
- Next in thread: Kurt Stutsman: "Re: cannot recognize vector as a vector, please help"
- Reply: Kurt Stutsman: "Re: cannot recognize vector as a vector, please help"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 29 Mar 2005 21:48:13 +0200
John Guo schrieb:
> Thanks Chris.
>
> The only thing I want to achieve is to have an array of constant
> strings predefined. It seems to me that if I use the vector of string
> approach, I have to initialize it by calling a function. This is
> awkward. I am originally using char[][], and init it in the namespace.
>
> Could someone suggest a more elegant approach to do the same thing?
You could use an accessor function:
typedef std::vector< std::string > PatternsMsgs;
const PatternMsgs& patternMsgs()
{
static PatternMsgs messages;
static bool initialised = false;
if ( !initialised )
{
// fill the vector
initialised = true;
}
return messages;
}
that is if the messages are constant. Make it return a non-const
reference otherwise.
Cheers,
Malte
- Next message: Julián Albo: "Re: Convert from std::vector<double> to std::vector<int>"
- Previous message: Zak: "Re: Exe will not start"
- In reply to: John Guo: "Re: cannot recognize vector as a vector, please help"
- Next in thread: Kurt Stutsman: "Re: cannot recognize vector as a vector, please help"
- Reply: Kurt Stutsman: "Re: cannot recognize vector as a vector, please help"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|