Guys,
Could someone tell me why the Progam Crashes. Here is the Code ...
Qt Code:
  1. #include <qapplication.h>
  2. #include <qguardedptr.h>
  3. class Employee{
  4. public:
  5. Employee( const QString& strName, int iSal ){
  6. m_strName = strName;
  7. m_iSalary = iSal;
  8. }
  9.  
  10. QString name() const {
  11. return m_strName;
  12. }
  13. void setName( const QString& strName ){
  14. m_strName = strName;
  15. }
  16.  
  17. int salary() const {
  18. return m_iSalary;
  19. }
  20.  
  21. void setSalary( int iSal ) {
  22. m_iSalary = iSal;
  23. }
  24.  
  25. operator QString() const {
  26. return m_strName + ", " + QString::number( m_iSalary );
  27. }
  28.  
  29. private:
  30. QString m_strName;
  31. int m_iSalary;
  32. };
  33.  
  34.  
  35. int main(int iArgs, char* aszArgs[] ) {
  36. QApplication app( iArgs, aszArgs );
  37.  
  38. QMap< int, QGuardedPtr<Employee> > mapIdToEmployee;
  39. mapIdToEmployee[ 0 ] = new Employee( "Sunil", 6000 ); //Crashes ??
  40.  
  41. if( ! mapIdToEmployee[0] ){
  42. qWarning( "Employee Destroyed !!! " );
  43. }
  44. else{
  45. qWarning( ( static_cast<QString>(*mapIdToEmployee[0]) ).ascii() );
  46. }
  47. return 0;
  48. }
To copy to clipboard, switch view to plain text mode