• 5967阅读
  • 5回复

QT语法 [复制链接]

上一主题 下一主题
离线小林由
 
只看楼主 倒序阅读 楼主  发表于: 2012-06-10
class People: public QObject{
public:
    People(){
    }
private:
    QString name;
private:
    QString age;
public:
    QString getName(){
        return this->name;
    }
    void setName(QString name){
        this->name = name;
    }

    QString getAge(){
        return age;
    }

    void setAge(QString age) {
        this->age = age;
    }
public:
    QString &operator<<(People stu){
        return this->name;
    }

    bool operator==(const People& other){
        return (name == other.getName());//这里编译不过,为什么呢
    }
};
QT的【面向对象,设计模式】是不是和VC++,一模一样的啊,有没有QT的关于这方面的书啊,貌似到处都是gui编程。求几本QT面向对象什么【thinging in QT】有木有啊
离线XChinux

只看该作者 1楼 发表于: 2012-06-11
看C++的面向对象方面的书
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线XChinux

只看该作者 2楼 发表于: 2012-06-11
QString getName(){
        return this->name;
    }

改成:

QString getName() const {
        return this->name;
    }
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线XChinux

只看该作者 3楼 发表于: 2012-06-11
你的参数const People &other, 这个other是const的,所以other.getName()要求不能对内部成员进行修改,所以getName()需要加const声明,表明它不会修改内部成员,否则是不能由const类型对象进行调用该方法的.
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线passion_wu
只看该作者 4楼 发表于: 2012-06-11
回 3楼(XChinux) 的帖子
版主对这么基础的问题还是回答得这么耐心,佩服至极。
离线小林由
只看该作者 5楼 发表于: 2012-06-11
非常感谢
快速回复
限100 字节
 
上一个 下一个