2024.9.6

 1> 手写unique_ptr智能指针

#include <iostream>
//#include <memory>
using namespace std;
//unique_ptr<AA> p0(new AA("西施"));// 分配内存并初始化。
template <typename T>
class unique_ptr
{
public:
    explicit unique_ptr(T p) noexcept; // 不可用于转换函数。
    ~unique_ptr() noexcept;
    T& operator*() const;  // 重载*操作符。
    T* operator->() const noexcept; // 重载->操作符。
    unique_ptr(const unique_ptr &) = delete; // 禁用拷贝构造函数
    unique_ptr& operator=(const unique_ptr &) = delete; // 禁用赋值函数
    unique_ptr(unique_ptr &&) noexcept; // 右值引用。
    unique_ptr& operator=(unique_ptr &&) noexcept; // 右值引用

private:
    T ptr; // 内置的指针。
};

template <typename T>
unique_ptr<T>::unique_ptr(T p)noexcept:ptr(p){}

template <typename T>
unique_ptr<T>::~unique_ptr() noexcept
{
    delete ptr;
}

template <typename T>
T& unique_ptr<T>::operator*() const
{
    return *ptr;
}

template <typename T>
T* unique_ptr<T>::operator->()const noexcept
{
    return ptr;
}

template <typename T>
unique_ptr<T>::unique_ptr(unique_ptr && other) noexcept :ptr(other.ptr)
{
    other.ptr = nullptr;
}

template <typename T>
unique_ptr<T>& unique_ptr<T>::operator=(unique_ptr && other) noexcept
{
    if(this != other.ptr)
    {
        delete ptr;
        ptr = other.ptr;
        other.ptr = nullptr;
    }
    return *this;
}
int main()
{

    cout << "Hello World!" << endl;
    return 0;
}

2> 手写登录界面,不允许拖拽,要求尽可能的美观

#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //this->setStyleSheet("background-color:pink;");
    this->setWindowOpacity(0.9);
    this->setWindowTitle("我是QQ");

    this->setFixedSize(600,600);
    this->btn1 = new QPushButton("登录",this);
    this->btn1->resize(300,50);
    this->btn1->move(200,500);
    this->btn1->setStyleSheet("background-color:skyblue; border-radius:10;");
    connect(this->btn1,&QPushButton::clicked,this,&Widget::login);

    //账户
    this->edit1 = new QLineEdit(this);
    this->edit1->resize(300,50);
    this->edit1->move(btn1->x(),btn1->y()-250);
    this->edit1->setPlaceholderText("账户");

    //密码
    this->edit2 = new QLineEdit(this);
    this->edit2->resize(300,50);
    this->edit2->move(btn1->x(),btn1->y()-150);
    this->edit2->setPlaceholderText("密码");
    this->edit2->setEchoMode(QLineEdit::Password);

    //账户label
    this->label1 = new QLabel("账户",this);
    this->label1->resize(70,50);
    this->label1->move(edit1->x()-70,edit1->y());

    //密码label
    this->label2 = new QLabel("密码",this);
    this->label2->resize(70,50);
    label2->move(edit2->x()-70,edit2->y());

    this->rdb = new QRadioButton(this);
    this->rdb->resize(70,50);
    this->rdb->move(label2->x(),label2->y()+label2->height()+50);
    //connect(this->rdb,&QRadioButton::clicked,);

    this->label3 = new QLabel("已阅读并同意服务协议和QQ隐私保护",this);
    this->label3->resize(300,50);
    this->label3->move(rdb->x()+30,rdb->y());
}

Widget::~Widget()
{
    delete ui;
}

void Widget::login()
{
    if(this->edit1->text() == this->edit2->text() && this->edit1->text() != ""  && this->edit1->text() != "")
    {
        qDebug() << "登陆成功";
        this->close();
    }
    else
    {
        qDebug() << "登陆失败";
    }
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值