C++ c++;:无法实例化std::设置模板类

C++ c++;:无法实例化std::设置模板类,c++,templates,std,C++,Templates,Std,给定以下类 template <typename T> class Plane { public: Plane<T>(T A, T B, T C, const Vector3<T>& vec): A(A), B(B), C(C), D(-1*A*vec.x-B*vec.y-C*vec.z) { } Plane<T>(): A(

给定以下类

template <typename T>
class Plane
{
public:
    Plane<T>(T A, T B, T C, const Vector3<T>& vec):
        A(A),
        B(B),
        C(C),
        D(-1*A*vec.x-B*vec.y-C*vec.z)
    {

    }

    Plane<T>():
        A(0),
        B(0),
        C(0),
        D(0)
    {

    }


    bool CalculateTime(const Vector3<T>& r0,  const Vector3<T>& rd, T& result )
    {
        Vector3<T> vec(A,B,C);

        if ( vec.dot(rd))
        {
            result = -1;
            return false;
        }
        else
        {
            result = (vec.dot(r0) + D)/vec.dot(rd);
            return true;
        }
    }

    T A;
    T B;
    T C;
    T D;
};
模板
类平面
{
公众:
平面(T A、T B、T C、常数向量3和向量):
A(A),,
B(B),,
C(C),
D(-1*A*vec.x-B*vec.y-C*vec.z)
{
}
平面():
A(0),
B(0),,
C(0),
D(0)
{
}
布尔计算时间(常数向量3和r0、常数向量3和rd、T和结果)
{
向量3-vec(A,B,C);
如果(矢量点(rd))
{
结果=-1;
返回false;
}
其他的
{
结果=(向量点(r0)+D)/向量点(rd);
返回true;
}
}
Tα;
tb;
tc;
td;
};
出于某种奇怪的原因,当我做以下事情时

    std::set<Plane<float> > s;
    s.insert(Plane<float>(10,20,30,Vector3f(10,30,40)));
std::set s;
s、 插入(平面(10,20,30,向量3F(10,30,40));

这产生了一个巨大的错误

1>          with
1>          [
1>              T=float
1>          ]
1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\xtree(2245) : see declaration of 'std::operator <'
1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef(179) : while compiling class template member function 'bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const'
1>          with
1>          [
1>              _Ty=Plane<float>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(559) : see reference to function template instantiation 'bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const' being compiled
1>          with
1>          [
1>              _Ty=Plane<float>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\type_traits(743) : see reference to class template instantiation 'std::less<_Ty>' being compiled
1>          with
1>          [
1>              _Ty=Plane<float>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\xtree(1028) : see reference to class template instantiation 'std::is_empty<_Ty>' being compiled
1>          with
1>          [
1>              _Ty=std::less<Plane<float>>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\set(44) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled
1>          with
1>          [
1>              _Traits=std::_Tset_traits<Plane<float>,std::less<Plane<float>>,std::allocator<Plane<float>>,false>
1>          ]
1>          c:\users\awesome2\google drive\university\eng 3gc3\assignment 3\voxelmodeler\voxelmodeler\voxelcube.h(44) : see reference to class template instantiation 'std::set<_Kty>' being compiled
1>          with
1>          [
1>              _Kty=Plane<float>
1>          ]
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef(180): error C2784: 'bool std::operator <(const std::move_iterator<_RanIt> &,const std::move_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::move_iterator<_RanIt> &' from 'const Plane<T>'
1>          with
1>          [
1>              T=float
1>          ]
1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1983) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef(180): 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 Plane<T>'
1>          with
1>          [
1>              T=float
1>          ]
1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1259) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef(180): error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const Plane<T>'
1>          with
1>          [
1>              T=float
1>          ]
1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1075) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef(180): 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 Plane<T>'
1>          with
1>          [
1>              T=float
1>          ]
1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\utility(232) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef(180): error C2676: binary '<' : 'const Plane<T>' does not define this operator or a conversion to a type acceptable to the predefined operator
1>          with
1>          [
1>              T=float
1>          ]
1>带有
1>          [
1> T=浮动
1>          ]
1> c:\program files(x86)\microsoft visual studio 11.0\vc\include\xtree(2245):请参见“std::operator”的声明设置
(如
multiset
map
multimap
)需要一个比较函数或运算符。未指定
set
multiset
map
multimap
时,使用
std::less
函数对象来协调集合中的元素。 所以你必须写这样的东西

template <typename T>
class Plane {
public:
    friend bool operator < (const Plane<T>& p1, const Plane<T>& p2)
    {
         return ???
    }
};
模板
类平面{
公众:
friend布尔运算符<(常数平面和p1、常数平面和p2)
{
回来
}
};
正如您所看到的,像集合中的平面这样的类不是一个好的类,可能更好的是一个
无序的集合
,或者只是一个
std::vector
集合
(如
multiset
map
multimap
)需要一个比较函数或操作符。未指定
set
multiset
map
multimap
时,使用
std::less
函数对象来协调集合中的元素。 所以你必须写这样的东西

template <typename T>
class Plane {
public:
    friend bool operator < (const Plane<T>& p1, const Plane<T>& p2)
    {
         return ???
    }
};
模板
类平面{
公众:
friend布尔运算符<(常数平面和p1、常数平面和p2)
{
回来
}
};

正如您所看到的,像集合中的平面这样的类不是一个好的类,可能最好是一个
无序的集合
,或者只是一个
std::vector
重要的部分在错误消息的末尾:

...
error C2676: binary '<' : 'const Plane<T>' does not define this operator
or a conversion to a type acceptable to the predefined operator
。。。

错误C2676:binary'重要部分位于错误消息的末尾:

...
error C2676: binary '<' : 'const Plane<T>' does not define this operator
or a conversion to a type acceptable to the predefined operator
。。。

错误C2676:二进制“您没有定义比较运算符。”
std::set
需要此项,或者需要专门化
std::less
。您没有定义比较运算符
std::set
需要此功能,或者需要专门化
std::less