'drv' 没有命名类型

'drv' does not name a type

找了一段时间,没找到答案。包括所有路径。我在我正在创建的 class 中的另一个名称空间中引用了 class。

我收到以下错误: src/app/Application.h:30:9: 错误:'drv' 没有命名类型

下面的代码。感谢您的帮助!

Main.cpp

int main(int argc, char** argv) {

    app::Application program;

    program.run();

    return 0;
}    

LEDs.h

#ifndef LEDS_H
#define LEDS_H

namespace drv {

    class LEDs {
    public:
        LEDs();
        void InitLEDs(void);
        void SetLEDs(const uint8_t value);
    private:
        static const uint8_t NUM_LEDs = 5;
    };
}

#endif  /* LEDS_H */

Application.h

#ifndef APPLICATION_H
#define APPLICATION_H

namespace app {

    enum State {
        NORMAL = 0,
        ZONE,
        PAIRING,
        STUCK,
        BATT,
        OFF
    };

    class Application {
    public:
        Application();
        void run(void);
        void execute_loop(void);
    private:
        bool IDLE;
        State STATE;
        drv::LEDs Leds; // LINE 30

    };
}
#endif  // APPLICATION_H 

Application.cpp

#include "stdint.h"
#include "stdbool.h"    
#include "../drv/LEDs.h"
#include "Application.h"

namespace app {

    Application::Application() {
        IDLE = false;
        STATE = NORMAL;
    }

    void Application::run(void) {
        Leds.InitLEDs();

        while(1)
        {
            if(IDLE) {
                PowerSaveIdle();
            }
            else {
                execute_loop();
            }
        }

    }

    void Application::execute_loop(void)
    {

    }

}

LEDs.cpp

#include <stdint.h>
#include "LEDs.h"

namespace drv {
    LEDs::LEDs() { 
    }

    void LEDs::InitLEDs() {
        SetLEDs(0xff);
    }

    void LEDs::SetLEDs(const uint8_t value) {
        //Removed for readability
    }
}

您在 Application.h 中缺少 #include ... 行。在该文件的顶部(或在包含保护之后)添加行

#include "LEDs.h"