Home > Mobile >  how can i convert a class which uses template to a normal class which uses Double
how can i convert a class which uses template to a normal class which uses Double

Time:04-02

I thought I was doing good using class templates. But as soon as I started going backwards I had some difficulties. My task is to remove the tempalte realtype class and replace it with a normal double. I really have no idea how to get started. My idea was to simply remove this line and I thought everything will work fine, but I get errors.

ArcBasis.hpp:

template <typename RealType>  //line to replace
class K_Arc_Basis
{
    public:
         DECLARE_K_STANDARD (Arc_Basis)

    private:
         typedef K_Arc_Basis<Double> ThisType;
         typedef K_Circle_Basis <Double> CircleType;
    public:
         K_Arc_Basis();
         K_Arc_Basis( const CircleType& Circle );
    private:
         PointType  m_Center;
         Double     m_Radius;
         Double     m_StartAngle;   
         Double     m_Arc;          
    };

ArcBasis.inl

template <typename RealType>//line to replace
inline K_Arc_Basis<RealType>::K_Arc_Basis()
: m_Center(), m_Radius (1), 
  m_StartAngle( 0 ), m_Arc( 2*KSRealPi( Double(0) ) )
 {
 }

template <typename RealType>//line to replace
inline K_Arc_Basis<RealType>::K_Arc_Basis( const CircleType& Circle )
: m_Center( Circle.Center() ), m_Radius( Circle.Radius() ), 
     m_StartAngle( 0 ), m_Arc( 2*KSRealPi( Double(0) ) )
  {
  }

CodePudding user response:

You haven't used the template type anywhere, but you have used a specialisation of that template (and also K_Circle_Basis?). You need to remove all the <Double> too.

class K_Arc_Basis
{
public:
     DECLARE_K_STANDARD (Arc_Basis) // what does this expand to??

private:
     typedef K_Arc_Basis ThisType;
     typedef K_Circle_Basis CircleType;
public:
     K_Arc_Basis();
     K_Arc_Basis( const CircleType& Circle );
private:
     PointType  m_Center; // What is PointType?
     double     m_Radius;
     double     m_StartAngle;   
     double     m_Arc;          
};

Alternately, you could start using the type parameter in your template, and provide some explicit instantiations

template <typename RealType>
class K_Arc_Basis
{
public:
     DECLARE_K_STANDARD (Arc_Basis)

private:
     using ThisType = K_Arc_Basis<RealType>;
     using CircleType = K_Circle_Basis<RealType>;
public:
     K_Arc_Basis();
     K_Arc_Basis( const CircleType& Circle );
private:
     PointType  m_Center;
     RealType   m_Radius;
     RealType   m_StartAngle;   
     RealType   m_Arc;          
};

using K_Arc_Basis_F = K_Arc_Basis<float>; // or whatever name
using K_Arc_Basis_D = K_Arc_Basis<double>; // or whatever name
  • Related