qualified-id in declaration before '(' token





  • Sorry, ich seh nicht, wie das mit meinem Problem zu tun hat 😉



  • @Blaubart
    Du wolltest ein String-Value in ein Int umwandeln.



  • Nein, ich wollte einen Wert aus der Config auslesen und benutzen. Zumindest in meiner letzten Frage.



  • Du mußt dann auch den Parameter value als Referenz (&) übergeben (so wie bei ProfileMap::Get) - oder alternativ als Rückgabewert der Funktion.

    Wenn du jedoch mehrere Werte auslesen willst, dann wäre es besser nur einmalig die Datei zu laden und dann nur noch die ProfileMap direkt zu benutzen (also ProfileMap configuration als Klassenmember erstellen - so daß du dann keine eigene Funktion für jeden Datentyp mehr erstellen brauchst).



  • vielen Dank. Ich will tatsächlich nur einen Wert auslesen.
    Aber der Aufruf scheint nicht zu stimmen:

    GetConfigInt("timeout", timeoutvalue, "/boot/config.uEnv");
    
    | src/OV/OpenVarioMenu.cpp:1027:16: error: expected identifier before string constant
    |  1027 |   GetConfigInt("timeout", timeoutvalue, "/boot/config.uEnv");
    |       |                ^~~~~~~~~
    | src/OV/OpenVarioMenu.cpp:1027:16: error: expected ',' or '...' before string constant
    | src/OV/OpenVarioMenu.cpp:1027:3: error: ISO C++ forbids declaration of 'GetConfigInt' with no type [-fpermissive]
    |  1027 |   GetConfigInt("timeout", timeoutvalue, "/boot/config.uEnv");
    |       |   ^~~~~~~~~~~~
    | src/OV/OpenVarioMenu.cpp:52:15: warning: 'void GetConfigInt(const string&, int&, const string&)' defined but not used [-Wunused-function]
    |    52 |   static void GetConfigInt(const string &keyvalue, int &value, const string &path)
    |       |               ^~~~~~~~~~~~
    | make: *** [build/compile.mk:107: output/UNIX/opt/src/OV/OpenVarioMenu.o] Error 1
    | ERROR: oe_runmake failed
    


  • Steht der Aufruf innerhalb einer Funktion?

    C++ ist einfach zu komplex, um mal eben, ohne die Grundlagen genau zu kennen, ein (fehlerfreies) Programm zu schreiben. Ansonsten mußt du halt jede einzelne Fehlermeldung im Internet recherchieren (ganz zu schweigen von Laufzeitfehlern).

    Dein Eingangsbeitrag sowie weitere Nachfragen wurden ja beantwortet.



  • diese Funktion steht so am Anfang der Datei, wie auch ChangeConfigInt, welche ja funktioniert.
    https://github.com/freevariode/XCSoar/blob/master/src/OV/OpenVarioMenu.cpp

     static void GetConfigInt(const string &keyvalue, int value, const string &path)
      {
        const Path ConfigPath(path.c_str());
    
        ProfileMap configuration;
        Profile::LoadFile(configuration, ConfigPath);
        configuration.Get(keyvalue.c_str(), value);
      }
    

    Der Aufruf erfolgt hier:

    class MainMenuWidget final
      : public RowFormWidget
    {
      enum Controls {
        XCSOAR,
        LOGBOOK,
        FILE,
        SYSTEM,
        SHELL,
        REBOOT,
        SHUTDOWN,
        TIMER,
      };
    
      UI::Display &display;
      UI::EventQueue &event_queue;
    
      WndForm &dialog;
    
      UI::Timer timer{[this](){
        if (--remaining_seconds == 0) {
          HideRow(Controls::TIMER);
          StartXCSoar();
        } else {
          ScheduleTimer();
        }
      }};
    
      GetConfigInt("timeout", timeoutvalue, "/boot/config.uEnv");
      unsigned remaining_seconds = 3;
    
    public:
      MainMenuWidget(UI::Display &_display, UI::EventQueue &_event_queue,
                     WndForm &_dialog) noexcept
        :RowFormWidget(_dialog.GetLook()),
         display(_display), event_queue(_event_queue),
         dialog(_dialog) {}
    
    private:
      void StartXCSoar() noexcept {
        const UI::ScopeDropMaster drop_master{display};
        const UI::ScopeSuspendEventQueue suspend_event_queue{event_queue};
        Run("/usr/bin/xcsoar", "-fly");
      }
    
      void ScheduleTimer() noexcept {
        assert(remaining_seconds > 0);
    
        timer.Schedule(std::chrono::seconds{1});
    
        char buffer[256];
        snprintf(buffer, sizeof(buffer), "Starting XCSoar in %u seconds (press any key to cancel)",
                 remaining_seconds);
        SetText(Controls::TIMER, buffer);
      }
    
      void CancelTimer() noexcept {
        timer.Cancel();
        remaining_seconds = 0;
        HideRow(Controls::TIMER);
      }
    
      /* virtual methods from class Widget */
      void Prepare(ContainerWindow &parent,
                   const PixelRect &rc) noexcept override;
    
      void Show(const PixelRect &rc) noexcept override {
        RowFormWidget::Show(rc);
        if (remaining_seconds > 0)
          ScheduleTimer();
      }
    
      void Hide() noexcept override {
        CancelTimer();
        RowFormWidget::Hide();
      }
    
      bool KeyPress(unsigned key_code) noexcept override {
        CancelTimer();
        return RowFormWidget::KeyPress(key_code);
      }
    };
    
    


  • Innerhalb einer Klasse (oder Struktur) können nur Definitionen und Funktionen stehen, keine Anweisungen (wie z.B. ein Funktionsaufruf).
    Packe diese Codezeile in eine eigene Funktion und rufe sie von außerhalb auf, oder führe sie z.B. im Konstruktor MainMenuWidget(...) { /* hier einfügen */ } hinzu.

    Außerdem hast du timeoutvalue nirgendwo definiert -> das wird die nächste Fehlermeldung erzeugen...



  • Mit der neuen Position lässt sich das Problem noch nicht lösen:

    public:
      MainMenuWidget(UI::Display &_display, UI::EventQueue &_event_queue,
                     WndForm &_dialog) noexcept
        :RowFormWidget(_dialog.GetLook()),
         display(_display), event_queue(_event_queue),
         dialog(_dialog) {}
         int timeoutvalue;
         GetConfigInt("timeout", timeoutvalue, "/boot/config.uEnv");
    
    private:
      void StartXCSoar() noexcept {
        const UI::ScopeDropMaster drop_master{display};
        const UI::ScopeSuspendEventQueue suspend_event_queue{event_queue};
        Run("/usr/bin/xcsoar", "-fly");
      }
    
    
    |   CXX     output/UNIX/opt/src/OV/OpenVarioMenu.o
    | src/OV/OpenVarioMenu.cpp:1036:19: error: expected identifier before string constant
    |  1036 |      GetConfigInt("timeout", timeoutvalue, "/boot/config.uEnv");
    |       |                   ^~~~~~~~~
    | src/OV/OpenVarioMenu.cpp:1036:19: error: expected ',' or '...' before string constant
    | src/OV/OpenVarioMenu.cpp:1036:6: error: ISO C++ forbids declaration of 'GetConfigInt' with no type [-fpermissive]
    |  1036 |      GetConfigInt("timeout", timeoutvalue, "/boot/config.uEnv");
    |       |      ^~~~~~~~~~~~
    | src/OV/OpenVarioMenu.cpp:52:15: warning: 'void GetConfigInt(const string&, int&, const string&)' defined but not used [-Wunused-function]
    |    52 |   static void GetConfigInt(const string &keyvalue, int &value, const string &path)
    |       |               ^~~~~~~~~~~~
    | make: *** [build/compile.mk:107: output/UNIX/opt/src/OV/OpenVarioMenu.o] Error 1
    | ERROR: oe_runmake failed
    
    

  • Mod

    Nur weil du Sachen einrückst, als ob sie zusammen gehören, heißt das nicht, dass sie zusammen gehören. C++ guckt nur auf Klammern & Co, nicht auf Leerzeichen.

    Ich muss mich hier meinen Vorrednern anschließen: Du musst C++ lernen, bevor du so etwas versuchst. Du kannst ja nicht einmal die Grammatik. Selbst wenn du ein grammatikalisch richtiges Programm hinbekommen solltest, ist das ja noch lange entfernt davon etwas sinnvolles, oder gar das was du willst zu tun. Du musst schließlich wissen, wo, wie und wieso du dein Funktion aufrufen willst. Wenn du mit deinem derzeitigen Kenntnisstand nicht einmal weißt, wie ein Programm abläuft, wie willst du das dann wissen?


Anmelden zum Antworten