Thread: Stl sets and custom classes.

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    271

    Stl sets and custom classes.

    Here we go again.

    With the help of you guys, I was able to use custom classes in vectors.

    http://cboard.cprogramming.com/showthread.php?t=79012

    Now, I have a need of sets and it turns out it's not straigtfoward.

    The book I'm looking at now (leen ammeral's stl for c++ programmers) shows how to use sets like this:
    Code:
    set<int, less<int> > S;
    set<int, less<int> >::iterator i;
    Well, I just tried it with the souped up custom class, the one with
    custom copy constructor, overloaded = operator or destructor
    and my compiler just told me very politely to go shove it up my colon.
    Code:
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139): error C2784: 'bool std::operator <(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const T1 *' from 'const phone'
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139): error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Ax> &' from 'const phone'
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139): 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,_Ax> &' from 'const phone'
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139): error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const phone'
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139): 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 phone'
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139): error C2676: binary '<' : 'const phone' does not define this operator or a conversion to a type acceptable to the predefined operator
    Now what do I do?

  2. #2
    Registered User
    Join Date
    Oct 2005
    Posts
    271
    Never mind. I think I got it.

    You have to define functions for the operators ==, !=, >, <. Right?

    Now I've got a bigger problem. Something I've never seen before:
    Code:
    c:\documents and settings\문태선\바탕 화면\ot_ok\ipa.h(171): fatal error C1001: INTERNAL COMPILER ERROR
            (compiler file 'msc1.cpp', line 2701) 
             Please choose the Technical Support command on the Visual C++ 
             Help menu, or open the Technical Support help file for more information

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    You should probably do what it tells you.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> You have to define functions for the operators ==, !=, >, <. Right?
    You only really have to define operator< for your class to work with set. It uses the less than operator to sort the elements you add.

    >> ipa.h(171): fatal error C1001: INTERNAL COMPILER ERROR
    You should probably post some of the code around where the error points to. There are some reasons this may happen that have to do with a bug in your code (although I can't remember them off the top of my head). A search for C1001: INTERNAL COMPILER ERROR might help give you clues as well.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help With Custom Dynamic Arrays
    By feso4 in forum C++ Programming
    Replies: 3
    Last Post: 06-29-2006, 01:05 PM