MSVC在我的班级成员函数上给出了错误C2039

时间:2013-02-26 17:38:03

标签: c++ class templates visual-c++ visual-studio-2012

这是我的班级:

template<class T>
class Point2d
{
public:
    Point2d( void )
        : x( (T)0 )
        , y( (T)0 )
    { }

    Point2d( T px, T py )
        : x( px )
        , y( py )
    { }

    Point2d( DirectX::XMFLOAT2 p )
        : x( (T)p.x )
        , y( (T)p.y )
    { }

    operator XMFLOAT2( void )
    {
        return XMFLOAT2( x, y );
    }

    Point2d<T> operator=( const Point2d& p )
    {
        if ( *this == p ) return *this;

        x = p.x;
        y = p.y;

        return *this;
    }

    Point2d<T> operator=( XMFLOAT2 p )
    {
        x = p.x;
        y = p.y;

        return *this;
    }

    Point2d<T>& operator*( T m )
    {
        return Point2d<T>( x * m, y * m );
    }

    Point2d<T>& operator*( const Point2d& m )
    {
        return Point2d<T>( x * m.x, y * m.y );
    }

    Point2d<T>& operator*=( T m )
    {
        x *= m;
        y *= m;
        return *this;
    }

    Point2d<T>& operator*=( const Point2d& m )
    {
        x *= m.x;
        y *= m.y;
        return *this;
    }

    Point2d<T>& operator/( T d )
    {
        return Point2d<T>( x / d, y / d );
    }

    Point2d<T>& operator/( const Point2d& d )
    {
        return Point2d<T>( x / d.x, y / d.y );
    }

    Point2d<T>& operator/=( T d )
    {
        x /= d;
        y /= d;
        return *this;
    }

    Point2d<T>& operator/=( const Point2d& d )
    {
        x /= d.x;
        y /= d.y;
        return *this;
    }

    Point2d<T>& operator +( const Point2d& v )
    {
        return Point2d<T>( x + (T)v.x, y + (T)v.y );
    }

    Point2d<T>& operator+=( const Point2d& v )
    {
        x += v.x;
        y += v.y;
        return *this;
    }

    Point2d<T>& operator -( const Point2d& v )
    {
        return Point2d<T>( x - v.x, y - v.y );
    }

    Point2d<T>& operator-=( const Point2d& v )
    {
        x -= v.x;
        y -= v.y;
        return *this;
    }

    bool operator==( const Point2d& v )
    {
        return (x == v.x) && (y == v.y);
    }

    float Distance( const Point2d& p )
    {
        return std::sqrt( ((p.x-x)*(p.x-x)) + ((p.y-y)*(p.y-y)) );
    }

    float Dot( Point2d<T> p )
    {
        return ((float)p.x*(float)x) + ((float)p.y*(float)y);
    }

    union {
        struct {
            T   x, y;
        };
        struct {
            T   width, height;
        };
        T component[2];
    };
};
typedef Point2d<float> Point2f;

当我尝试在课堂上使用Dot函数时,MSVC告诉我(在编译时)给我error C2039: 'Dot' : is not a member of 'Point2d<T>'

文字示例代码:

Point2f test( 10.0f, -1.0f );
float result = test.Dot( Point2f( 5.0f, 2.0f ) );

我不知道为什么MSVC会将其标记为不是成员。

0 个答案:

没有答案