C++: Cannot find preferences library

kmn08_
Posts: 1
Joined: Thu Aug 15, 2019 12:32 pm

C++: Cannot find preferences library

Postby kmn08_ » Thu Aug 15, 2019 12:37 pm

I'm new to C++, and trying to write a class.

This class uses the Preferences library imported with #include <Preferences.h> as visible at the top

The issue is that I'm getting error messages when trying to use it in the .h file.

I've tried moving it to main, the errors went away and the Parameters object was successfully created after a test run.

I've been researching the error in vain, no club how to fix this ...

The class code (snippet of the header file):

Code: Select all

    #ifndef PHX_WIFI
    #define PHX_WIFI
    
    #include <Arduino.h>
    #include <Preferences.h>
    
    
    #include "WiFiConfig.h"
    
    class wifi {
    
        Preferences preferences;
    
        std::string preferencesNamespace = "WiFiConfig";
        std::string preferencesKey_SSID = "SSID";
        std::string preferencesKey_Password = "password";
    
        public:
        
        WiFiConfig getStoredConfig(void);  
    
    
    } ;
    
    #endif

The error in a screenshot:
Screen Shot 2019-08-15 at 1.38.26 PM.png
Screen Shot 2019-08-15 at 1.38.26 PM.png (446.27 KiB) Viewed 83 times

Code structure :

Code: Select all

    src
    |___main.cpp
    |___PHX/
        |___PHX.h
        |___wifi.h
        |___wifi.cpp
       
contents of PHX.h:

Code: Select all


    namespace PHX
    {
        
        #include "wifi.h"
        #include "WiFiConfig.h"
    
    } // namespace PHX
       
When used in main.cpp, works without problem :

Screen Shot 2019-08-15 at 1.45.06 PM.png
Screen Shot 2019-08-15 at 1.45.06 PM.png (310.81 KiB) Viewed 83 times

boarchuz
Posts: 110
Joined: Tue Aug 21, 2018 5:28 am

Re: C++: Cannot find preferences library

Postby boarchuz » Fri Aug 16, 2019 8:34 am

It's because you're in the PHX namespace there. Try "::Preferences preferences;"

Who is online

Users browsing this forum: No registered users and 10 guests