C2784 triggered by STL::Set insert() and find()

O

Olumide

Hello,

I've got this nice inner class that I'm holds a set of "FrontPoint"
objects as shown below. Unfortunately, the find and insert methods
trigger massive C2784 errors. Would someone please point out what I'm
doing wrong?

Many thanks,

- Olumide


//////////////////////// code ////////////////////////

struct FrontPoint
{
// stuff
};

class Cell
{
public:
double xMin , xMax, yMin, yMax , zMin , zMax;
Cell *upper , *lower , *north, *south, *east , *west;
Cell::Cell(){ upper = lower = north = south = east = west = NULL; }
set<FrontPoint > frontPoint;

void addFrontPoint( FrontPoint& frontPt )
{
frontPoint.insert( frontPt ); // Triggers C2784
}

void removeFrontPoint( FrontPoint& frontPt )
{
set<FrontPoint >::iterator frontPtItx =
frontPoint.find( frontPt ); // Triggers C2784
}
};


//////////////////////// error ////////////////////////

c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2784: 'bool std::eek:perator <(const
std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not
deduce template argument for 'const
std::basic_string<_Elem,_Traits,_Ax> &' from 'const
MarchingTriangles::FrontPoint'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\string(148) : see declaration of 'std::eek:perator`<''
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(138) : while compiling class-template member function
'bool std::less<_Ty>::eek:perator ()(const _Ty &,const _Ty &) const'
with
[
_Ty=MarchingTriangles::FrontPoint
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\set(48) : see reference to class template instantiation
'std::less<_Ty>' being compiled
with
[
_Ty=MarchingTriangles::FrontPoint
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\xtree(23) : see reference to class template instantiation
'std::_Tset_traits<_Kty,_Pr,_Alloc,_Mfl>' being compiled
with
[
_Kty=MarchingTriangles::FrontPoint,
_Pr=std::less<MarchingTriangles::FrontPoint>,
_Alloc=std::allocator<MarchingTriangles::FrontPoint>,
_Mfl=false
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\xtree(65) : see reference to class template instantiation
'std::_Tree_nod<_Traits>' being compiled
with
[

_Traits=std::_Tset_traits<MarchingTriangles::FrontPoint,std::less<MarchingTriangles::FrontPoint>,std::allocator<MarchingTriangles::FrontPoint>,false>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\xtree(87) : see reference to class template instantiation
'std::_Tree_ptr<_Traits>' being compiled
with
[

_Traits=std::_Tset_traits<MarchingTriangles::FrontPoint,std::less<MarchingTriangles::FrontPoint>,std::allocator<MarchingTriangles::FrontPoint>,false>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\xtree(105) : see reference to class template instantiation
'std::_Tree_val<_Traits>' being compiled
with
[

_Traits=std::_Tset_traits<MarchingTriangles::FrontPoint,std::less<MarchingTriangles::FrontPoint>,std::allocator<MarchingTriangles::FrontPoint>,false>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\set(57) : see reference to class template instantiation
'std::_Tree<_Traits>' being compiled
with
[

_Traits=std::_Tset_traits<MarchingTriangles::FrontPoint,std::less<MarchingTriangles::FrontPoint>,std::allocator<MarchingTriangles::FrontPoint>,false>
]
c:\Work\Project\MuscleBuilder\MarchingTriangles.h(72) : see
reference to class template instantiation 'std::set<_Kty>' being
compiled
with
[
_Kty=MarchingTriangles::FrontPoint
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2784: 'bool std::eek:perator <(const _Elem
*,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce
template argument for 'const T1 *' from 'const
MarchingTriangles::FrontPoint'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\string(138) : see declaration of 'std::eek:perator`<''
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2784: 'bool std::eek:perator <(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 MarchingTriangles::FrontPoint'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\string(128) : see declaration of 'std::eek:perator`<''
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2784: 'bool std::eek:perator <(const
std::list<_Ty,_Alloc> &,const std::list<_Ty,_Alloc> &)' : could not
deduce template argument for 'const std::list<_Ty,_Ax> &' from 'const
MarchingTriangles::FrontPoint'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\list(991) : see declaration of 'std::eek:perator`<''
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2784: 'bool std::eek:perator <(const
std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce
template argument for 'const std::_Tree<_Traits> &' from 'const
MarchingTriangles::FrontPoint'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\xtree(1170) : see declaration of 'std::eek:perator`<''
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2784: 'bool std::eek:perator <(const
std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could
not deduce template argument for 'const std::vector<_Ty,_Ax> &' from
'const MarchingTriangles::FrontPoint'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\vector(915) : see declaration of 'std::eek:perator`<''
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2784: 'bool std::eek:perator <(const
std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt>
&)' : could not deduce template argument for 'const
std::reverse_iterator<_RanIt> &' from 'const
MarchingTriangles::FrontPoint'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\xutility(655) : see declaration of 'std::eek:perator`<''
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2784: 'bool std::eek:perator <(const
std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not
deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from
'const MarchingTriangles::FrontPoint'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\utility(73) : see declaration of 'std::eek:perator`<''
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2676: binary '<' : 'const
MarchingTriangles::FrontPoint' does not define this operator or a
conversion to a type acceptable to the predefined operator
MarchingTriangles.cpp
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2784: 'bool std::eek:perator <(const
std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not
deduce template argument for 'const
std::basic_string<_Elem,_Traits,_Ax> &' from 'const
MarchingTriangles::FrontPoint'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\string(148) : see declaration of 'std::eek:perator`<''
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(138) : while compiling class-template member function
'bool std::less<_Ty>::eek:perator ()(const _Ty &,const _Ty &) const'
with
[
_Ty=MarchingTriangles::FrontPoint
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\set(48) : see reference to class template instantiation
'std::less<_Ty>' being compiled
with
[
_Ty=MarchingTriangles::FrontPoint
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\xtree(23) : see reference to class template instantiation
'std::_Tset_traits<_Kty,_Pr,_Alloc,_Mfl>' being compiled
with
[
_Kty=MarchingTriangles::FrontPoint,
_Pr=std::less<MarchingTriangles::FrontPoint>,
_Alloc=std::allocator<MarchingTriangles::FrontPoint>,
_Mfl=false
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\xtree(65) : see reference to class template instantiation
'std::_Tree_nod<_Traits>' being compiled
with
[

_Traits=std::_Tset_traits<MarchingTriangles::FrontPoint,std::less<MarchingTriangles::FrontPoint>,std::allocator<MarchingTriangles::FrontPoint>,false>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\xtree(87) : see reference to class template instantiation
'std::_Tree_ptr<_Traits>' being compiled
with
[

_Traits=std::_Tset_traits<MarchingTriangles::FrontPoint,std::less<MarchingTriangles::FrontPoint>,std::allocator<MarchingTriangles::FrontPoint>,false>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\xtree(105) : see reference to class template instantiation
'std::_Tree_val<_Traits>' being compiled
with
[

_Traits=std::_Tset_traits<MarchingTriangles::FrontPoint,std::less<MarchingTriangles::FrontPoint>,std::allocator<MarchingTriangles::FrontPoint>,false>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\set(57) : see reference to class template instantiation
'std::_Tree<_Traits>' being compiled
with
[

_Traits=std::_Tset_traits<MarchingTriangles::FrontPoint,std::less<MarchingTriangles::FrontPoint>,std::allocator<MarchingTriangles::FrontPoint>,false>
]
c:\Work\Project\MuscleBuilder\MarchingTriangles.h(72) : see
reference to class template instantiation 'std::set<_Kty>' being
compiled
with
[
_Kty=MarchingTriangles::FrontPoint
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2784: 'bool std::eek:perator <(const _Elem
*,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce
template argument for 'const T1 *' from 'const
MarchingTriangles::FrontPoint'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\string(138) : see declaration of 'std::eek:perator`<''
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2784: 'bool std::eek:perator <(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 MarchingTriangles::FrontPoint'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\string(128) : see declaration of 'std::eek:perator`<''
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2784: 'bool std::eek:perator <(const
std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could
not deduce template argument for 'const std::vector<_Ty,_Ax> &' from
'const MarchingTriangles::FrontPoint'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\vector(915) : see declaration of 'std::eek:perator`<''
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2784: 'bool std::eek:perator <(const
std::list<_Ty,_Alloc> &,const std::list<_Ty,_Alloc> &)' : could not
deduce template argument for 'const std::list<_Ty,_Ax> &' from 'const
MarchingTriangles::FrontPoint'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\list(991) : see declaration of 'std::eek:perator`<''
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2784: 'bool std::eek:perator <(const
std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce
template argument for 'const std::_Tree<_Traits> &' from 'const
MarchingTriangles::FrontPoint'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\xtree(1170) : see declaration of 'std::eek:perator`<''
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2784: 'bool std::eek:perator <(const
std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt>
&)' : could not deduce template argument for 'const
std::reverse_iterator<_RanIt> &' from 'const
MarchingTriangles::FrontPoint'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\xutility(655) : see declaration of 'std::eek:perator`<''
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2784: 'bool std::eek:perator <(const
std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not
deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from
'const MarchingTriangles::FrontPoint'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\utility(73) : see declaration of 'std::eek:perator`<''
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2676: binary '<' : 'const
MarchingTriangles::FrontPoint' does not define this operator or a
conversion to a type acceptable to the predefined operator
 
R

red floyd

Olumide said:
Hello,

I've got this nice inner class that I'm holds a set of "FrontPoint"
objects as shown below. Unfortunately, the find and insert methods
trigger massive C2784 errors. Would someone please point out what I'm
doing wrong?

Among other things, you're not posting a minimal compilable example
which exhibits the behavior in question -- see FAQ 5.8 --
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8
//////////////////////// code ////////////////////////

struct FrontPoint
{
// stuff
};

class Cell
{
public:
double xMin , xMax, yMin, yMax , zMin , zMax;
Cell *upper , *lower , *north, *south, *east , *west;
Cell::Cell(){ upper = lower = north = south = east = west = NULL; }
set<FrontPoint > frontPoint;

void addFrontPoint( FrontPoint& frontPt )
{
frontPoint.insert( frontPt ); // Triggers C2784
}

void removeFrontPoint( FrontPoint& frontPt )
{
set<FrontPoint >::iterator frontPtItx =
frontPoint.find( frontPt ); // Triggers C2784
}
};


//////////////////////// error ////////////////////////

c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include
\functional(139) : error C2784: 'bool std::eek:perator <(const
std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not
deduce template argument for 'const
std::basic_string<_Elem,_Traits,_Ax> &' from 'const
MarchingTriangles::FrontPoint'

OK, Where and what is MarchingTriangles?
[remainder redacted]
 
O

Olumide

I've got this nice inner class that ... holds a set of "FrontPoint"
objects as shown below. Unfortunately, the find and insert methods
trigger massive C2784 errors. Would someone please point out what I'm
doing wrong?

Among other things, you're not posting a minimal compilable example
which exhibits the behavior in question -- see FAQ 5.8 --http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8

...

OK, Where and what is MarchingTriangles?
[remainder redacted]

Oops ... Its the name of the parent class of 'FrontPoint' and 'Cell',
and its quite complex, but it worked perfectly, at least it did until
I added add and remove methods to the inner class 'Cell'. Anyway, I
may have solved the problem, by overloading < in the 'FrontPoint',
which I had to change from a struct to a class like so:

class FrontPoint
{
public:
// stuff

bool operator<( const FrontPoint &frontPt );
friend bool operator<(const FrontPoint& frontPt1 , const FrontPoint&
frontPt2 );
};


Interestingly, the code compiles even though, the both "operator<"
methods aren't (yet) implemented. I wonder if I can get away with not
implementing them ... I'm not trying to be cheeky. I just want to know
if the error is due to a fussy compiler that wrongly assumes these
methods will be called.
 
K

Kai-Uwe Bux

Olumide said:
I've got this nice inner class that ... holds a set of "FrontPoint"
objects as shown below. Unfortunately, the find and insert methods
trigger massive C2784 errors. Would someone please point out what I'm
doing wrong?

Among other things, you're not posting a minimal compilable example
which exhibits the behavior in question -- see FAQ 5.8
--http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8

...

OK, Where and what is MarchingTriangles?
[remainder redacted]

Oops ... Its the name of the parent class of 'FrontPoint' and 'Cell',
and its quite complex, but it worked perfectly, at least it did until
I added add and remove methods to the inner class 'Cell'. Anyway, I
may have solved the problem, by overloading < in the 'FrontPoint',
which I had to change from a struct to a class like so:

In C++, the only difference between a struct and a class is whether things
are public or private by default. In particular, structs can have methods.
Your coding guidelines, however, may require you to change from struct to
class when you add methods.

class FrontPoint
{
public:
// stuff

bool operator<( const FrontPoint &frontPt );
friend bool operator<(const FrontPoint& frontPt1 , const FrontPoint&
frontPt2 );
};


Interestingly, the code compiles even though, the both "operator<"
methods aren't (yet) implemented. I wonder if I can get away with not
implementing them ... I'm not trying to be cheeky. I just want to know
if the error is due to a fussy compiler that wrongly assumes these
methods will be called.

You _should_ get an error (either from the compiler or the linker) if there
is actually an insertion into a std::set< FrontPoint >. The container
std::set<> _will_ use the operator< to determine order and equivalence of
entries. If you don't get an error, something in your code is really messed
up.


Best

Kai-Uwe Bux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top