Compiler error: enum class nach function

OP #7379260
Lesenswert?

Hallo, meine C-Skills sind etwas angestaubt 🥴 … könnte mir jemand kurz erklären warum dieser Code

1
void foo() { }
2
enum class Foo {bar};
3
bool bar(Foo arg) { return arg == Foo::bar; }
4
void setup() {}
5
void loop() {}

einen Compiler-Fehler wirft

1
(3:10: error: 'Foo' was not declared in this scope)

… aber keinen Fehler wirf wenn ich Zeile 1 und 2 vertausche?

(Firma: Gast) #7379279
Lesenswert?

Thomas F. schrieb:

meine C-Skills

Du meinst C++, oder?

Thomas F. schrieb:

… aber keinen Fehler wirf wenn ich Zeile 1 und 2 vertausche?

Das kann ich bestätigen!

Es wirft bei mi r folgende Meldungen:

1
sketch_mar25f:3:10: error: 'Foo' was not declared in this scope; did you mean 'foo'?
2
    3 | bool bar(Foo arg) { return arg == Foo::bar; }
3
      |          ^~~
4
      |          foo
5
sketch_mar25f:3:17: error: 'bool bar(Foo)' redeclared as different kind of entity
6
    3 | bool bar(Foo arg) { return arg == Foo::bar; }
7
      |                 ^
8
E:\Programme\arduino\portable\sketchbook\sketch_mar25f\sketch_mar25f.ino:3:6: note: previous declaration 'bool bar'
9
    3 | bool bar(Foo arg) { return arg == Foo::bar; }
10
      |      ^~~
11
cc1plus.exe: warning: unrecognized command line option '-Wno-volatile'
12
exit status 1
13
'Foo' was not declared in this scope; did you mean 'foo'?

avr-gcc-9.2.0 und C++17

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren