Qt工作笔记-各种构造函数汇总以及运算符重载(入门必备)
生活随笔
收集整理的這篇文章主要介紹了
Qt工作笔记-各种构造函数汇总以及运算符重载(入门必备)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
關鍵是源碼!
程序運行截圖如下:
源碼如下:
#include <QCoreApplication> #include <QDebug>class Test{public:int m_valueInt;QString m_valueStr;Test(){m_valueInt = -1;m_valueStr = "";}Test(const int valueInt, const QString valueStr){this->m_valueInt = valueInt;this->m_valueStr = valueStr;}Test(const Test &test){this->m_valueInt = test.m_valueInt;this->m_valueStr = test.m_valueStr;}Test &operator = (Test &test){this->m_valueInt = test.m_valueInt;this->m_valueStr = test.m_valueStr;return *this;}friend QDebug operator << (QDebug os, Test test){os << "(" << test.m_valueInt << ", "<< test.m_valueStr << ")";return os;} };int main(int argc, char *argv[]) {QCoreApplication a(argc, argv);Test test;qDebug() << "test:" << test;Test test2(10010, "中國連通");qDebug() << "test2:" << test2;Test test3(test2);qDebug() << "test3:" << test3;Test test4 = test3;qDebug() << "test4:" << test4;return a.exec(); }?
總結
以上是生活随笔為你收集整理的Qt工作笔记-各种构造函数汇总以及运算符重载(入门必备)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qt学习笔记-编写简易的音乐播放器
- 下一篇: Qt工作笔记-使用QFileSystem