user57182: I am programming an Arduino.  In the same .ino file as setup() and loop() I have defined the following:
void setup()
{
  // setup code
}

enum class CYCLE { TypeA, TypeB };

String cycleToString (CYCLE cycle) {
  if (cycle == CYCLE::TypeA) {
    return "TypeA";
  }
  else if (cycle == CYCLE::TypeB) {
    return "TypeB";
  }
  return "Undefined";
}

void loop()
{
  // loop code
}

But on compiling it gives the error:
sketch_v1:37:22: error: 'CYCLE' was not declared in this scope
 String cycleToString (CYCLE cycle) {
                      ^
/Users/.../sketch_v1.ino: In function 'String cycleToString(CYCLE)':
sketch_v1:37:31: error: 'String cycleToString(CYCLE)' redeclared as different kind of symbol
 String cycleToString (CYCLE cycle) {
                                  ^
/Users/.../sketch_v1.ino:37:8: note: previous declaration 'String cycleToString'
 String cycleToString (CYCLE cycle) {
        ^

Note that the enum class is fine and works as intended but if I try to add the function relying on the CYCLE type it then errors.

user31105: Note this is not an answer, since your code compiles perfectly. (adding a default/empty setup/loop function).
However, I want to give some improvements that cannot fit in a comment:

(optional) Align { and } under each other. Some put the { behind the line, some on a new line; this is mostly preference. But aligning { and } is mostly more clear.
Put each type/enum value on a new line; this makes it easier to add comments above/after it.
Except for trivial cases, never return from a statement, except the last one. In your case the function is quite simple, but still it's better to keep the return only at the end of a function.
Use a switch statement instead of multiple if statements.

So you get:
enum class CYCLE 
{
  TypeA, 
  TypeB 
};

String cycleToString (CYCLE cycle) 
{
  String str;

  switch (cycle)
  {
  case CYCLE::TypeA:
    str = "TypeA";
    break;

  case CYCLE::TypeB:
    str = "TypeB";
    break;

  default:
    str = "Undefined";
    break;
  }

  return str;
}


user37622: This is a known bug of Arduino builder, if you have functions before structs, classes or enums in sketch.
The sketch:
void foo() {
}

enum class CYCLE { TypeA, TypeB };

String cycleToString (CYCLE cycle) {
  if (cycle == CYCLE::TypeA) {
    return "TypeA";
  }
  else if (cycle == CYCLE::TypeB) {
    return "TypeB";
  }
  return "Undefined";
}

void setup() {
}

void loop() {
}

is processed to this .cpp file
#include <Arduino.h>
#line 1 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
#line 1 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"

#line 2 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
void foo();
#line 7 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
String cycleToString(CYCLE cycle);
#line 17 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
void setup();
#line 22 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
void loop();
#line 2 "/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino"
void foo() {
}

enum class CYCLE { TypeA, TypeB };

String cycleToString (CYCLE cycle) {
  if (cycle == CYCLE::TypeA) {
    return "TypeA";
  }
  else if (cycle == CYCLE::TypeB) {
    return "TypeB";
  }
  return "Undefined";
}

void setup() {
}

void loop() {
}

as you can see the forward declarations of functions are before the first function so before the enum.
The workaround for this bug is to follow good practice and declare all the structs, enums and classes before the first function definition.

57182: <p>I am programming an Arduino.  In the same .ino file as <code>setup()</code> and <code>loop()</code> I have defined the following:</p>

<pre><code>void setup()
{
  // setup code
}

enum class CYCLE { TypeA, TypeB };

String cycleToString (CYCLE cycle) {
  if (cycle == CYCLE::TypeA) {
    return "TypeA";
  }
  else if (cycle == CYCLE::TypeB) {
    return "TypeB";
  }
  return "Undefined";
}

void loop()
{
  // loop code
}
</code></pre>

<p>But on compiling it gives the error:</p>

<pre><code>sketch_v1:37:22: error: 'CYCLE' was not declared in this scope
 String cycleToString (CYCLE cycle) {
                      ^
/Users/.../sketch_v1.ino: In function 'String cycleToString(CYCLE)':
sketch_v1:37:31: error: 'String cycleToString(CYCLE)' redeclared as different kind of symbol
 String cycleToString (CYCLE cycle) {
                                  ^
/Users/.../sketch_v1.ino:37:8: note: previous declaration 'String cycleToString'
 String cycleToString (CYCLE cycle) {
        ^
</code></pre>

<p>Note that the <code>enum class</code> is fine and works as intended but if I try to add the function relying on the <code>CYCLE</code> type it then errors.</p>
 31105: <p>Note this is not an answer, since your code compiles perfectly. (adding a default/empty setup/loop function).</p>

<p>However, I want to give some improvements that cannot fit in a comment:</p>

<ol>
<li>(optional) Align { and } under each other. Some put the { behind the line, some on a new line; this is mostly preference. But aligning { and } is mostly more clear.</li>
<li>Put each type/enum value on a new line; this makes it easier to add comments above/after it.</li>
<li>Except for trivial cases, never return from a statement, except the last one. In your case the function is quite simple, but still it's better to keep the return only at the end of a function.</li>
<li>Use a <code>switch</code> statement instead of multiple <code>if</code> statements.</li>
</ol>

<p>So you get:</p>

<pre><code>enum class CYCLE 
{
  TypeA, 
  TypeB 
};

String cycleToString (CYCLE cycle) 
{
  String str;

  switch (cycle)
  {
  case CYCLE::TypeA:
    str = "TypeA";
    break;

  case CYCLE::TypeB:
    str = "TypeB";
    break;

  default:
    str = "Undefined";
    break;
  }

  return str;
}
</code></pre>
 37622: <p>This is a known bug of Arduino builder, if you have functions before structs, classes or enums in sketch.</p>
<p>The sketch:</p>
<pre><code>void foo() {
}

enum class CYCLE { TypeA, TypeB };

String cycleToString (CYCLE cycle) {
  if (cycle == CYCLE::TypeA) {
    return &quot;TypeA&quot;;
  }
  else if (cycle == CYCLE::TypeB) {
    return &quot;TypeB&quot;;
  }
  return &quot;Undefined&quot;;
}

void setup() {
}

void loop() {
}
</code></pre>
<p>is processed to this .cpp file</p>
<pre><code>#include &lt;Arduino.h&gt;
#line 1 &quot;/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino&quot;
#line 1 &quot;/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino&quot;

#line 2 &quot;/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino&quot;
void foo();
#line 7 &quot;/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino&quot;
String cycleToString(CYCLE cycle);
#line 17 &quot;/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino&quot;
void setup();
#line 22 &quot;/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino&quot;
void loop();
#line 2 &quot;/tmp/arduino_modified_sketch_327776/sketch_jun23a.ino&quot;
void foo() {
}

enum class CYCLE { TypeA, TypeB };

String cycleToString (CYCLE cycle) {
  if (cycle == CYCLE::TypeA) {
    return &quot;TypeA&quot;;
  }
  else if (cycle == CYCLE::TypeB) {
    return &quot;TypeB&quot;;
  }
  return &quot;Undefined&quot;;
}

void setup() {
}

void loop() {
}
</code></pre>
<p>as you can see the forward declarations of functions are before the first function so before the enum.</p>
<p>The workaround for this bug is to follow good practice and declare all the structs, enums and classes before the first function definition.</p>
