1

これが私のクラスです:

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 がメンバーではないというフラグを立てる理由がわかりません。

4

0 に答える 0