Suppose I have a class that has many data members of various types and may add more in the future
Class A { public: int getA(); void setA(int a); ... private: int m_a; int m_b; double m_c; string m_d; CustomerType m_e; char * m_f; ... }
The problem is this: every time I add another data item, I need to add a get / set function. For some reason, I cannot change them publicly.
one solution is to use the getType / setType function along with the template:
Class A { public: int getInt(int id){ switch(id) case ID_A: return m_a; case ID_B: return m_b; ... } void setInt(int id,int i){...} double getDouble(){...} void setDouble(int id,double d){...} ... template<T> T get(); template<>
Is there a better solution? Thanks.
source share