Thread: Errors related with <set>

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    12

    Question Errors related with <set>

    it's simple code, but I got errors.

    insert
    Code:
    #include <stdio.h>
    #include <set>
    
    struct mytemp
    {
    	int a;
    	int b;
    };
    
    void main(){
    
    	typedef std::set < mytemp > mSet;
    	mSet pool;
    
    	mytemp T;
    	T.a=1;
    	T.b=1;
    
    	pool.insert(T);
    	
    	printf("%d\n",pool.end());
    
    }
    I got the following error messages after compilation with VC++6.0

    insert
    Code:
    Compiling...
    Test1.cpp
    c:\program files\microsoft visual studio\vc98\include\functional(86) : error C2784: 'bool __cdecl std::operator <(const class std::multiset<_K,_Pr,_A> &,const class std::multiset<_K,_Pr,_A> &)' : could not deduce template argument for 'const class s
    td::multiset<_K,_Pr,_A> &' from 'const struct mytemp'
            c:\program files\microsoft visual studio\vc98\include\functional(86) : while compiling class-template member function 'bool __thiscall std::less<struct mytemp>::operator ()(const struct mytemp &,const struct mytemp &) const'
    c:\program files\microsoft visual studio\vc98\include\functional(86) : error C2784: 'bool __cdecl std::operator <(const class std::set<_K,_Pr,_A> &,const class std::set<_K,_Pr,_A> &)' : could not deduce template argument for 'const class std::set<_K
    ,_Pr,_A> &' from 'const struct mytemp'
            c:\program files\microsoft visual studio\vc98\include\functional(86) : while compiling class-template member function 'bool __thiscall std::less<struct mytemp>::operator ()(const struct mytemp &,const struct mytemp &) const'
    c:\program files\microsoft visual studio\vc98\include\functional(86) : error C2784: 'bool __cdecl std::operator <(const class std::_Tree<_K,_Ty,_Kfn,_Pr,_A> &,const class std::_Tree<_K,_Ty,_Kfn,_Pr,_A> &)' : could not deduce template argument for 'c
    onst class std::_Tree<_K,_Ty,_Kfn,_Pr,_A> &' from 'const struct mytemp'
            c:\program files\microsoft visual studio\vc98\include\functional(86) : while compiling class-template member function 'bool __thiscall std::less<struct mytemp>::operator ()(const struct mytemp &,const struct mytemp &) const'
    c:\program files\microsoft visual studio\vc98\include\functional(86) : error C2784: 'bool __cdecl std::operator <(const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &,const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &)' : could not deduce te
    mplate argument for 'const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &' from 'const struct mytemp'
            c:\program files\microsoft visual studio\vc98\include\functional(86) : while compiling class-template member function 'bool __thiscall std::less<struct mytemp>::operator ()(const struct mytemp &,const struct mytemp &) const'
    c:\program files\microsoft visual studio\vc98\include\functional(86) : error C2784: 'bool __cdecl std::operator <(const struct std::pair<_T1,_T2> &,const struct std::pair<_T1,_T2> &)' : could not deduce template argument for 'const struct std::pair<
    _T1,_T2> &' from 'const struct mytemp'
            c:\program files\microsoft visual studio\vc98\include\functional(86) : while compiling class-template member function 'bool __thiscall std::less<struct mytemp>::operator ()(const struct mytemp &,const struct mytemp &) const'
    c:\program files\microsoft visual studio\vc98\include\functional(86) : error C2676: binary '<' : 'const struct mytemp' does not define this operator or a conversion to a type acceptable to the predefined operator
            c:\program files\microsoft visual studio\vc98\include\functional(86) : while compiling class-template member function 'bool __thiscall std::less<struct mytemp>::operator ()(const struct mytemp &,const struct mytemp &) const'
    Error executing cl.exe.
    
    Test1.exe - 6 error(s), 0 warning(s)
    Does anyone know why this happens?

  2. #2
    Registered User
    Join Date
    Jun 2007
    Posts
    12
    Ok, this problem is settled, a redefination of the operator '<' in the struct mytemp
    will work.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    #1.
    If you're really set on using printf in a C++ program, then you should prefer <cstdio> to <stdio.h>, otherwise use <iostream> and cout.

    #2.
    Code:
    void main
    Ugh, there are many (some quite recent) posts about this.

    #3.
    Code:
    pool.end()
    This is a pointer (iterator) to one element past the end of the container. Trying to print that value is going to get you an address (that doesn't point to anything valid).
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doxygen failing
    By Elysia in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 04-16-2008, 01:24 PM
  2. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  3. opengl Nehe tutorial errors when compiling
    By gell10 in forum Game Programming
    Replies: 4
    Last Post: 07-14-2003, 08:09 PM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM