خرید بک لینک

Vote count: 0

I am now leaing how to use boost::geometry library, and I am following the tutorial, where type traits are introduced to make the codes more genetic. For example, the distance function below is regarded as genetic by using traits:

struct mypoint
{
    double x, y;
};

template <typename P1, typename P2>
double distance(P1 const& a, P2 const& b)
{
    double dx = get<0>(a) - get<0>(b);
    double dy = get<1>(a) - get<1>(b);
    retu std::sqrt(dx * dx + dy * dy);
}

template <typename P1, typename P2>
double distance(P1 const& a, P2 const& b)
{
    double dx = get<0>(a) - get<0>(b);
    double dy = get<1>(a) - get<1>(b);
    retu std::sqrt(dx * dx + dy * dy);
}

namespace traits
{
    template <>
    struct access<mypoint, 0>
    {
        static double get(mypoint const& p)
        {
            retu p.x;
        }
    };

    template <>
    struct access<mypoint, 1>
    {
        static double get(mypoint const& p)
        {
            retu p.y;
        }
    };

}

However, when I compile the codes, the following compilation errors happen:

Error   3   error C2913: explicit specialization; 'traits::access' is not a specialization of a class template  

Any ideas? Thanks.

asked 24 secs ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 14 تير 1395 ساعت: 23:01

صفحه بندی