Guys,
Could someone tell me why the Progam Crashes. Here is the Code ...
#include <qapplication.h>
#include <qguardedptr.h>
class Employee{
public:
Employee( const QString& strName, int iSal ){
m_strName = strName;
m_iSalary = iSal;
}
return m_strName;
}
void setName( const QString& strName ){
m_strName = strName;
}
int salary() const {
return m_iSalary;
}
void setSalary( int iSal ) {
m_iSalary = iSal;
}
return m_strName
+ ", " + QString::number( m_iSalary
);
}
private:
int m_iSalary;
};
int main(int iArgs, char* aszArgs[] ) {
QMap< int, QGuardedPtr<Employee> > mapIdToEmployee;
mapIdToEmployee[ 0 ] = new Employee( "Sunil", 6000 ); //Crashes ??
if( ! mapIdToEmployee[0] ){
qWarning( "Employee Destroyed !!! " );
}
else{
qWarning( ( static_cast<QString>(*mapIdToEmployee[0]) ).ascii() );
}
return 0;
}
#include <qapplication.h>
#include <qguardedptr.h>
class Employee{
public:
Employee( const QString& strName, int iSal ){
m_strName = strName;
m_iSalary = iSal;
}
QString name() const {
return m_strName;
}
void setName( const QString& strName ){
m_strName = strName;
}
int salary() const {
return m_iSalary;
}
void setSalary( int iSal ) {
m_iSalary = iSal;
}
operator QString() const {
return m_strName + ", " + QString::number( m_iSalary );
}
private:
QString m_strName;
int m_iSalary;
};
int main(int iArgs, char* aszArgs[] ) {
QApplication app( iArgs, aszArgs );
QMap< int, QGuardedPtr<Employee> > mapIdToEmployee;
mapIdToEmployee[ 0 ] = new Employee( "Sunil", 6000 ); //Crashes ??
if( ! mapIdToEmployee[0] ){
qWarning( "Employee Destroyed !!! " );
}
else{
qWarning( ( static_cast<QString>(*mapIdToEmployee[0]) ).ascii() );
}
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks