L
L
l2p2014-09-08 20:09:00
Qt
l2p, 2014-09-08 20:09:00

How can I properly inherit a class?

There is a class:

class one : public QObject
{
      Q_OBJECT
      int per;

public:
      one(int per) { this->per = per; }
};

Who inherits:
class two : public one {};
When calling two *r = new two(123); it says no matching function to call to 'one::one(int&)'
Please tell me what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
tsarevfs, 2014-09-08
@l2p

constructors are not inherited.

class one
{
public:
   Q_OBJECT
   one(int a)
   {
   }
};

class two : one
{
public:
   Q_OBJECT
   two(int a)
      :one(a)
   {
   }
};
int main()
{
   one * s = new two(1);
   return 0;
}

A
AlexP11223, 2014-09-08
@AlexP11223

Two also needs Q_OBJECT.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question