指向不同类模板的通用指针

时间:2015-12-09 15:39:16

标签: c++ templates pointers

我有一个模板类,如图所示。

template <class T>
class CValueEdit : public TextAreaWithOneWildcard
{
public:
CValueEdit() : m_bIsSelected(false)
{
    m_Value = (T)0;
    m_Step = (T)1;
    m_MaxBoundary = (T)1;
    m_MinBoundary = (T)0;

}
void setBoundaryValues(T max, T min)
{
    m_MaxBoundary = max;
    m_MinBoundary = min;
}
void setValue(T value)
{
    m_Value = value;
}
void setStep(T step)
{
    m_Step = step;
}
void incrementValue() // ++ operator overloading can be used here
{
    m_Value += m_Step;
}
void decrementValue() // -- operator overloading can be used here
{
    m_Value -= m_Step;
}
void getValue(T& ref_Value)
{
    ref_Value = m_Value;
}
virtual void handleClickEvent()
{
    m_bIsSelected = true;
}
bool isSelected()
{
    return m_bIsSelected;
}

~CValueEdit(){}

private:

T m_Value, m_MaxBoundary, m_MinBoundary, m_Step;
bool m_bIsSelected;


};

我正在使用此类来存储可能是float或int的值。 TextAreaWithOneWildCard是触敏应用程序的窗口小部件类。 窗口中将有多个ValueEdit对象。

例如:

ValueEdit<float> m_pressure[3];
ValueEdit<int> m_time[3];

我需要在父窗口中注册触摸的窗口小部件的地址。

为此,我需要一个可以指向ValueEdit<float>ValueEdit<int>的通用指针。我该如何声明指针?

如果用户触摸一个小部件,我希望此小部件注册指针

1 个答案:

答案 0 :(得分:0)

我认为你应该注册一个指向EmailController::sendemail($ticketdata->email,$ticketdata); 的指针。然后有一些缺失:你会用这个指针做什么?如果您需要调用例如TextAreaWithOneWildcard,那么您可以以某种方式公开setValue(T value)类型(例如使用专用方法)并使用dynamic_cast。

这一行:

TextAreaWithOneWildcard

然后

class CValueEditBase : public TextAreaWithOneWildcard
{
public:
    enum type_e {int_e, float_e} ;
    virtual type_e type(void) const = 0 ; 
}
相关问题