Qt: default value of variable in class
- by Martin
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; 
};