לגבי מערך שמורכב מ- float int ו- string, איך

לגבי מערך שמורכב מ- float int ו- string, איך

אפשר לשרשר את סכום איברי המערך באופן כזה שאם מדובר בשני איברים מספריים מדובר בסכומם ואם מדובר באיבר אחד מספרי והשני ליטרלי ל- לשרשר את האחרון לראשון. מצ"ב קוד אפשרי והשאלה היא איך לחשב את totalSum ???
#include <string.h> using namespace std; class GeneralTypeWrapper { public: protected: virtual void AddYourself(); private: }; class IntWrapper:GeneralTypeWrapper { public: IntWrapper(int value) { m_Int=value; } virtual void AddYourself(GeneralTypeWrapper & totalSum) { totalSum+=m_Int; } protected: private: int m_Int; }; class FloatWrapper:GeneralTypeWrapper { public: FloatWrapper(float value) { m_Float=value; } protected: virtual void AddYourself(GeneralTypeWrapper & totalSum) { totalSum+=m_Float; } private: float m_Float; }; class StringWrapper:GeneralTypeWrapper { public: StringWrapper(string value) { m_String=value; } protected: virtual void AddYourself(GeneralTypeWrapper & totalSum) { totalSum+=m_String; } private: string m_String; }; class TypesArray { public: TypesArray() { m_CurrIndex=0; } void InsertElement(GeneralTypeWrapper * currElem) { m_TypesArr[m_CurrIndex++]=currElem; } void PrintSum() { for (int i=0;i<m_CurrIndex;i++) { m_TypesArr->AddYourself(totalSum); } } protected: private: GeneralTypeWrapper * m_TypesArr[1000]; int m_CurrIndex; };
 
למעלה