gpt4 book ai didi

c++ - 我们什么时候应该使用 * , & , . , ->?

转载 作者:太空宇宙 更新时间:2023-11-04 14:38:39 24 4
gpt4 key购买 nike

为什么我们在创建 button 时使用 * 字符,但我们没有将它添加到 app 实例?

#include <QApplication>
#include <QPushButton>

int main(int argc,char *argv[])
{
QApplication app(argc,argv);
QPushButton *button = new QPushButton("Button Text");
QObject::connect(button,SIGNAL(clicked()),&app,SLOT(quit()));
button->show();
return app.exec();
}

什么时候应该使用*&.->

最佳答案

  • 当您想要访问结构变量的成员时,您应该使用 .
  • 当您想要声明指向某物(例如结构)的指针时,您应该使用 *
  • 当你想从变量中获取指向某物的指针时,你应该使用 &
  • 当您想从指针访问结构的成员时,您应该使用 ->

关于c++ - 我们什么时候应该使用 * , & , . , ->?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3012181/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com