D
D
Dmitry2016-04-20 11:55:34
C++ / C#
Dmitry, 2016-04-20 11:55:34

Why does the compiler throw a "not a type" error when using forward declaration?

Good day, toasters.
I have two header files with source code:
report.h

#ifndef __REPORT_H
#define __REPORT_H

namespace HidDevice {

class Device;

class Report {
    // реализация родительского класса
};

struct SetModeReport : public Report {
    public:
        SendModeReport() :
                Report(M_REPORT, M_REPORT_LEN),
                mode(Device::Mode::UNDEFENDED)
        { };

        ~SendModeReport() { };

        Device::Mode mode;

        // остальные методы и поля

    private:
        // приватная область
};

}; // HidDevice namespace

#endif //__REPORT_H

hidDevice.h
#ifndef __HID_H
#define __HID_H

#include "report.h"

namespace HidDevice {

class Device
{
public:

    //! List of HID device states
    enum Mode {
        NORMAL = 0,             /*!< Mode of sending angles */
        CALIB_WHEEL,            /*!< Calibration wheel mode */
        CALIB_RUDDER,           /*!< Calibration rudder mode */
        SAVE_TABLE_WHEEL,       /*!< Save wheel calibration into flash memory */
        SAVE_TABLE_RUDDER,      /*!< Save rudder calibration into flash memory */
        END_SAVE_TABLE,         /*!< End of table saving */
        CALC_CRC,               /*!< Calculate CRC of both tables */
        END_CALC_CRC,           /*!< End of calculating CRC */
        UNDEFENDED              /*!< "Do nothing" mode */
    };

    void sendData(Report& report);
    // другие поля и методы
};

}; // HidDevice namespace

#endif //__HID_H

Actually, after trying to compile, the compiler swears as follows:
inc\hid\report.h|97|error: 'Mode' in 'class HidDevice::Device' does not name a type|

Although, it seems, to prevent exactly this error, I used forward declaration in the file report.h :
namespace HidDevice {

class Device;

....

}; // HidDevice namespace

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2016-04-20
@looogle

You need to use scoped enum from C++11, they can be forward declared among other things. In this case, the enumeration can be removed from the class.
If it is not possible to enable C++11 support, then you will have to explicitly enable it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question