[英]How do I call the constructor of a class' member?
I wanted to declare a QGraphicsView
which has a previously declared member as an argument of the constructor, but the compiler interprets it as a function.我想声明一个QGraphicsView
,它有一个先前声明的成员作为构造函数的参数,但编译器将它解释为一个函数。
(Code for reference) (代码供参考)
class Widnow : public QMainWindow
{
Q_OBJECT
// constructors, member functions, etc...
private:
Ui::Widnow *ui;
QTimer timer01;
QGraphicsScene gaem;
QGraphicsView wiev(&gaem); //this gets interpreted as a function
}
Trying to call the constructor as QGraphicsView wiev = QGraphicsView(&gaem);
试图将构造函数调用为QGraphicsView wiev = QGraphicsView(&gaem);
also causes an error, as the copy constructor has been deleted... Is there a way to declare this member without errors?也会导致错误,因为复制构造函数已被删除......有没有办法在没有错误的情况下声明这个成员?
The C++ compiler thinks that it is a method declaration where "wiev" as method that returns an instance of QGraphicsView. C++ 编译器认为它是一个方法声明,其中“wiev”作为返回 QGraphicsView 实例的方法。 Use this way用这种方式
class Widnow : public QMainWindow
{
private:
QGraphicsScene gaem;
QGraphicsView wiev; //this gets interpreted as a function
public:
Widnow() : wiev(&gaem)
{}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.