hi everyone.
I'm having some strange problems with the STL in C++.
I have this code:
for(i=0; i<theTree.size(); ++i)
{ //Look if the rule already exits
for(j=leftSides.begin(); j!=leftSides.end(); ++j)
{
if((*j).rule.type==theTree[0].type && strcmp((*j).rule.text, theTree[0].text))
{
break;
}
}
//If it exists add the lefts side
if(j!=leftSides.end())
{
(*j).parts.insert(theTree[1]);
}
else
{
//If it does not exists, push it and add left side
tempList.rule=theTree[0];
tempSet.insert(theTree[1]);
tempList.parts=tempSet;
leftSides.pushBack(tempList);
}
}
The definitions are:
std::vector<std::vector<struct token> > theTree;
std::vector<struct parts_list>leftSides;
std::set<struct token> tempSet;
struct parts_list tempList;
All this is part of a little compiler i'm implementing, but when i try to compile the code it gives me this:
g++ main.cpp cLexicParser.cpp cSyntaxParser.cpp -o grammar
cSyntaxParser.cpp: En la función miembro ‘void cSyntaxParser::PrintTree()’:
cSyntaxParser.cpp:75:46: aviso: formato ‘%d’ espera un argumento de tipo ‘int’, pero el argumento 2 es de tipo ‘std::vector<std::vector<token> >::size_type {aka long unsigned int}’ [-Wformat]
cSyntaxParser.cpp: En la función miembro ‘bool cSyntaxParser::createLeftSides()’:
cSyntaxParser.cpp:142:14: error: ‘class std::vector<parts_list>’ no tiene un miembro llamado ‘pushBack’
cSyntaxParser.cpp: En el ámbito global:
cSyntaxParser.cpp:148:42: error: no hay una función miembro ‘bool cSyntaxParser::createRightSides()’ declarada en la clase ‘cSyntaxParser’
cSyntaxParser.cpp:153:41: error: no hay una función miembro ‘void cSyntaxParser::LS(token)’ declarada en la clase ‘cSyntaxParser’
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/bits/stl_tree.h:65:0,
from /usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/set:60,
from structs.h:3,
from cSyntaxParser.h:1,
from cSyntaxParser.cpp:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/bits/stl_function.h: En la función miembro ‘bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [con _Tp = token]’:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/bits/stl_tree.h:1277:4: instanciado desde ‘std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(const _Val&) [con _Key = token, _Val = token, _KeyOfValue = std::_Identity<token>, _Compare = std::less<token>, _Alloc = std::allocator<token>]’
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/bits/stl_set.h:410:29: instanciado desde ‘std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename _Alloc::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [con _Key = token, _Compare = std::less<token>, _Alloc = std::allocator<token>, typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename _Alloc::rebind<_Key>::other>::const_iterator = std::_Rb_tree_const_iterator<token>, std::set<_Key, _Compare, _Alloc>::value_type = token]’
cSyntaxParser.cpp:140:32: instanciado desde aquí
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/bits/stl_function.h:236:22: error: no hay coincidencia para ‘operator<’ en ‘__x < __y’
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/bits/stl_function.h:236:22: nota: los candidatos son:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/bits/stl_pair.h:207:5: nota: template<class _T1, class _T2> bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/bits/stl_iterator.h:291:5: nota: template<class _Iterator> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/bits/stl_iterator.h:341:5: nota: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_IteratorL>&, const std::reverse_iterator<_IteratorR>&)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/bits/stl_tree.h:866:5: nota: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator<(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/bits/stl_set.h:713:5: nota: template<class _Key, class _Compare, class _Alloc> bool std::operator<(const std::set<_Key, _Compare, _Alloc>&, const std::set<_Key, _Compare, _Alloc>&)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/bits/stl_multiset.h:696:5: nota: template<class _Key, class _Compare, class _Alloc> bool std::operator<(const std::multiset<_Key, _Compare, _Alloc>&, const std::multiset<_Key, _Compare, _Alloc>&)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/include/g++-v4/bits/stl_vector.h:1290:5: nota: template<class _Tp, class _Alloc> bool std::operator<(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
which is quite chaotic.
I can't use any pair utility because it also yield this same error message.
Can someone tell me what's going on?
BTW, sorry, the compiler is in spanish, although i think it can be understood.