ошибка компилятора в классе с датамембером типа typedef map> MapPairList ;? - PullRequest
0 голосов
/ 09 марта 2012

Вот мой код.

класс XYZ.

#include <iostream>
#include <vector>
#include <map>

using namespace std;

typedef map<std::string,std::pair<std::string,vector<int>>> MapPairList;

class xyz
{
private:
    MapPairList m1;

public:
    void insert();
    string GetType(string& filetype);
    vector<int> GetExtList(string& filetype);
};

Реализация вышеуказанного класса.

    #include "xyz.h"

void xyz::insert()
{
    vector<int> v1;
    v1.push_back(1);
    v1.push_back(2);
    v1.push_back(3);

    vector<int> v2;
    v2.push_back(1);
    v2.push_back(2);
    v2.push_back(3);

    vector<int> v3;
    v3.push_back(1);
    v3.push_back(2);
    v3.push_back(3);

    string c1 = "type1";
    string f1 ="filetype1";
    string c2 = "type2";
    string f2 ="filetype2";
    string c3 = "type3";
    string f3 ="filetype3";

    m1.insert(make_pair(f1,make_pair(c1,v1)));
    m1.insert(make_pair(f2,make_pair(c2,v2)));
    m1.insert(make_pair(f3,make_pair(c3,v3)));
}

string xyz::GetType(std::string &filetype)
{
    MapPairList::iterator iter = m1.find(filetype);

    if(iter != m1.end())
    {
        return (*iter).second.first;
    }
}

vector<int> xyz::GetExtList(std::string &filetype)
{
    MapPairList::iterator iter = m1.find(filetype);

    if(iter != m1.end())
        return (*iter).second.second;
}

int main()
{
    xyz *x = new xyz();

    string out("filetype1");
    string in = x->GetType(out);
    cout<<in.c_str();

    delete x;
    return 0;
}

И когда я пытаюсь скомпилировать, я получаю следующие ошибки:

1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
1>        c:\program files\microsoft visual studio 8\vc\include\xtree(1372) : see declaration of 'std::operator <'
1>        c:\program files\microsoft visual studio 8\vc\include\functional(142) : while compiling class template member function 'bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const'
1>        with
1>        [
1>            _Ty=std::string
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\map(72) : see reference to class template instantiation 'std::less<_Ty>' being compiled
1>        with
1>        [
1>            _Ty=std::string
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\xtree(26) : see reference to class template instantiation 'std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>' being compiled
1>        with
1>        [
1>            _Kty=std::string,
1>            _Ty=std::pair<std::string,std::vector<int>>,
1>            _Pr=std::less<std::string>,
1>            _Alloc=std::allocator<std::pair<const std::string,std::pair<std::string,std::vector<int>>>>,
1>            _Mfl=false
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\xtree(68) : see reference to class template instantiation 'std::_Tree_nod<_Traits>' being compiled
1>        with
1>        [
1>            _Traits=std::_Tmap_traits<std::string,std::pair<std::string,std::vector<int>>,std::less<std::string>,std::allocator<std::pair<const std::string,std::pair<std::string,std::vector<int>>>>,false>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\xtree(94) : see reference to class template instantiation 'std::_Tree_ptr<_Traits>' being compiled
1>        with
1>        [
1>            _Traits=std::_Tmap_traits<std::string,std::pair<std::string,std::vector<int>>,std::less<std::string>,std::allocator<std::pair<const std::string,std::pair<std::string,std::vector<int>>>>,false>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\xtree(112) : see reference to class template instantiation 'std::_Tree_val<_Traits>' being compiled
1>        with
1>        [
1>            _Traits=std::_Tmap_traits<std::string,std::pair<std::string,std::vector<int>>,std::less<std::string>,std::allocator<std::pair<const std::string,std::pair<std::string,std::vector<int>>>>,false>
1>        ]
1>        c:\program files\microsoft visual studio 8\vc\include\map(82) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled
1>        with
1>        [
1>            _Traits=std::_Tmap_traits<std::string,std::pair<std::string,std::vector<int>>,std::less<std::string>,std::allocator<std::pair<const std::string,std::pair<std::string,std::vector<int>>>>,false>
1>        ]
1>        c:\documents and settings\apoos\my documents\visual studio 2005\projects\algos\maplistpair\xyz.h(12) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled
1>        with
1>        [
1>            _Kty=std::string,
1>            _Ty=std::pair<std::string,std::vector<int>>
1>        ]
1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
1>        c:\program files\microsoft visual studio 8\vc\include\xtree(1372) : see declaration of 'std::operator <'
1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
1>        c:\program files\microsoft visual studio 8\vc\include\xtree(1372) : see declaration of 'std::operator <'
1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
1>        c:\program files\microsoft visual studio 8\vc\include\xtree(1372) : see declaration of 'std::operator <'
1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const std::string'
1>        c:\program files\microsoft visual studio 8\vc\include\vector(1276) : see declaration of 'std::operator <'
1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const std::string'
1>        c:\program files\microsoft visual studio 8\vc\include\vector(1276) : see declaration of 'std::operator <'
1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const std::string'
1>        c:\program files\microsoft visual studio 8\vc\include\vector(1276) : see declaration of 'std::operator <'
1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const std::string'
1>        c:\program files\microsoft visual studio 8\vc\include\vector(1276) : see declaration of 'std::operator <'
1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string'
1>        c:\program files\microsoft visual studio 8\vc\include\xutility(1880) : see declaration of 'std::operator <'
1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string'
1>        c:\program files\microsoft visual studio 8\vc\include\xutility(1880) : see declaration of 'std::operator <'
1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string'
1>        c:\program files\microsoft visual studio 8\vc\include\xutility(1880) : see declaration of 'std::operator <'
1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string'
1>        c:\program files\microsoft visual studio 8\vc\include\xutility(1880) : see declaration of 'std::operator <'
1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string'
1>        c:\program files\microsoft visual studio 8\vc\include\utility(76) : see declaration of 'std::operator <'
1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string'
1>        c:\program files\microsoft visual studio 8\vc\include\utility(76) : see declaration of 'std::operator <'
1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string'
1>        c:\program files\microsoft visual studio 8\vc\include\utility(76) : see declaration of 'std::operator <'
1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string'
1>        c:\program files\microsoft visual studio 8\vc\include\utility(76) : see declaration of 'std::operator <'
1>c:\program files\microsoft visual studio 8\vc\include\functional(143) : error C2676: binary '<' : 'const std::string' does not define this operator or a conversion to a type acceptable to the predefined operator

На самом деле я пытаюсь использовать только конкретную структуру данных.

Если у вас есть лучшее решение для замены этой структуры данных другой, пожалуйста, предложите это. Отображение элемента является контейнером один к одному между первой и второй строками. И один ко многим между элементом в паре. Вот почему последний элемент в паре является вектором. Кто-нибудь может сказать мне, что пошло не так?

Ответы [ 2 ]

3 голосов
/ 09 марта 2012

Вы не включили <string>.Добавьте #include <string> перед typedef....

2 голосов
/ 09 марта 2012

г ++ говорит error: ‘>>’ should be ‘> >’ within a nested template argument list

Измените typedef на:

typedef map<std::string,std::pair<std::string,vector<int> > > MapPairList;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...