Qt: default value of variable in class

Posted by Martin on Stack Overflow See other posts from Stack Overflow or by Martin
Published on 2010-03-21T16:46:43Z Indexed on 2010/03/21 16:51 UTC
Read the original article Hit count: 192

Filed under:
|
|
|
|

When creating my own class in Qt I would like my variables in the class to have a standard/default value if I haven't set them to anything. It would be perfect if this was possible to set in the h-file so I don't have to do it in each instance method of my class. You can see what I want to do in the code below. In the example myBool would have the value of false and myInt the value of 0 when the object have been created. Is this possible at all?

In myclass.h:

class MyClass
{
    Q_OBJECT

public:
MyClass();
   ~MyClass();
    bool myBool = false; //I want to set myBool and myInt to a default/standard value
    int myInt = 0; 
};

© Stack Overflow or respective owner

Related posts about qt

Related posts about class