• 7012阅读
  • 3回复

C++语法2 [复制链接]

上一主题 下一主题
离线小林由
 
只看楼主 倒序阅读 楼主  发表于: 2012-06-11
【People.h】
#ifndef PEOPLE_H_
#define PEOPLE_H_

class People: public QObject{
public:
    People(){
    }
private:
    QString name;
private:
    QString age;
public:
    QString getName() const{
        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);

    bool operator==(const People& other);

    void a();
};


#endif /* PEOPLE_H_ */
【People.cpp】
#include <People.h>


void People::a(void){
}  //这个方法正常,为什么下个方法就报错呢

QString People::&operator<<(People stu){
}   //此方法格式错误
在线XChinux

只看该作者 1楼 发表于: 2012-06-11
楼主,你得巩固一下C++基础语法知识啊.

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

只看该作者 2楼 发表于: 2012-06-15
QString &  是返回值类型哈!顶一楼
离线realfan

只看该作者 3楼 发表于: 2013-02-06
引用第2楼xiaowu311于2012-06-15 16:54发表的  :
QString &  是返回值类型哈!顶一楼

就是返回QString的引用
快速回复
限100 字节
 
上一个 下一个