#pragma once#include <iostream>#include <sstream>usingnamespace std;class CHexToInt{ string m_strId; ///< Class adress stored as stringunsignedint m_iId; ///< Class adress stored as integerpublic: CHexToInt(); ~CHexToInt();};
2. In class constructor
CHexToInt::CHexToInt(){ stringstream stream;// Convert class adress to string stream << this; m_strId = stream.str(); cout << "m_strId = " << m_strId << endl;// Convert class adress to integer m_iId = (int) this; cout << "m_iId = " << m_iId << endl;// Convert integer back to hexadecimalchar strHexa[10]; sprintf(strHexa, "%x", m_iId); cout << "Int to Hex = " << strHexa << endl;// Test Int to Hex by cout cout << "Hex number = " << hex << m_strId << endl << endl;}
2.1. Convert class adress to a string m_strId
stringstream stream;// Convert hexadecimal class adress to stringstream << this;m_strId = stream.str();
2.2. Convert class adress to integer m_iId
m_iId = (int) this;
2.3 Check if int value is correct. Convert int to hex and compare with class adress.
// Convert integer back to hexadecimalchar strHexa[10];sprintf(strHexa, "%x", m_iId);cout << "Int to Hex = " << strHexa << endl;// Test Int to Hex by coutcout << "Hex number = " << hex << m_strId << endl << endl;