将QDateTime作为指针传递

时间:2016-06-02 13:14:29

标签: c++ qt

我有一个功能

void func(QDateTime* date) {}

当我想通过我需要做的当前日期时

QDateTime now = QDateTime::currentDateTimeUtc();
QDateTime *pnow = &now;
func(pnow);

有缩写吗?

func(*QDateTime::currentDateTimeUtc());

不起作用

func(&QDateTime::currentDateTimeUtc());

给出:获取临时[-fpermissive]

的地址

1 个答案:

答案 0 :(得分:1)

除非您想稍后将其用于其他目的,否则您不会需要变量来存储指针。你可以写

QDateTime now = QDateTime::currentDateTimeUtc();
func(&now);