I'm trying to initialize an object of my class using constructor with initializer_list.
The code is following:
QueryBuilder::QueryBuilder(std::initializer_list<std::string> list)
{
std::cout << "QueryBuilder constructor begin" << std::endl;
std::cout << "List size: " << list.size() << std::endl;
for(const auto& element : list)
{
std::cout << "List element: " << element << std::endl;
query_.tokens_.emplace_back(new NameEqualToken(element));
}
std::cout << "QueryBuilder constructor end" << std::endl;
}
Unfortunately, during execution of this part I have always got the memory fault.
Console output:
QueryBuilder constructor begin
List size: 2857706971
List element: Path
and then some random characters (program is trying to read the second element, which does not exists) finalized by memory fault.
It looks like the size of the initializer_list, passed to the constructor, is invalid.
The constructor is called in the following way:
pf.add(QueryBuilder{"Path"} , appbolo.iPath);
PS I have also tried with const char* as a initializer list template parameter type.
Can anyone tell me what I'm doing wrong ?
I'm using gcc 4.7.3 (crosscompiler armv7).
Aucun commentaire:
Enregistrer un commentaire