user23571: I made a new Arduino IDE project ABC, and am given ABC.ino. Then I create a XYZ.h and XYZ.cpp.

ABC.ino:
#include "XYZ.h"

void setup() {}
void loop() {}

XYZ.h:
#ifndef XYZ
#define XYZ

#include "Arduino.h"

class XYZ { };

#endif

XYZ.cpp:
#include "Arduino.h"
#include "XYZ.h"


When I try to compile this, I get some error:
In file included from sketch/XYZ.cpp:2:0:
XYZ:8: error: abstract declarator '<anonymous class>' used as declaration
 };
 ^
exit status 1
abstract declarator '<anonymous class>' used as declaration


However, when I rename my class to something other than the file name, like XYZa, the compilation succeeds.

Why can't I have the same name class as the file? 
I've done C++ projects (independent of Arduino) via Xcode and nano, and this has never been a problem.

user4143: #define XYZ
...
class XYZ { };

After preprocessing, what do you think that ends up as?

user84: #define XYZ

class XYZ { };

The first line tells the "C preprocessor" (called before C and C++ compilers) to replace XYZ with nothing everywhere it happens, hence after preprocessing, and before compiling, that code becomes:
#define XYZ

class  { };

This is where C++ compiler complains. It has nothing to do with your file name.
Among C and C++ programmers, it is commonly admitted that header files should be protected by macros named after the file name including the extension:
#ifndef XYZ_H
#define XYZ_H

If you use this practice, you won't have this problem anymore.

23571: <p>I made a new Arduino IDE <code>project ABC</code>, and am given <code>ABC.ino</code>. Then I create a <code>XYZ.h</code> and <code>XYZ.cpp</code>.</p>

<hr>

<p><code>ABC.ino</code>:</p>

<pre><code>#include "XYZ.h"

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

<p><code>XYZ.h</code>:</p>

<pre><code>#ifndef XYZ
#define XYZ

#include "Arduino.h"

class XYZ { };

#endif
</code></pre>

<p><code>XYZ.cpp</code>:</p>

<pre><code>#include "Arduino.h"
#include "XYZ.h"
</code></pre>

<hr>

<p>When I try to compile this, I get some error:</p>

<pre><code>In file included from sketch/XYZ.cpp:2:0:
XYZ:8: error: abstract declarator '&lt;anonymous class&gt;' used as declaration
 };
 ^
exit status 1
abstract declarator '&lt;anonymous class&gt;' used as declaration
</code></pre>

<hr>

<p>However, when I rename my class to something other than the file name, like <code>XYZa</code>, the compilation succeeds.</p>

<hr>

<p><strong>Why can't I have the same name class as the file?</strong> </p>

<p>I've done C++ projects (independent of Arduino) via <code>Xcode</code> and <code>nano</code>, and this has never been a problem.</p>
 4143: <pre><code>#define XYZ
...
class XYZ { };
</code></pre>

<p>After preprocessing, what do you think that ends up as?</p>
 84: <pre><code>#define XYZ

class XYZ { };
</code></pre>

<p>The first line tells the "C preprocessor" (called before C and C++ compilers) to replace <code>XYZ</code> with nothing everywhere it happens, hence after preprocessing, and before compiling, that code becomes:</p>

<pre><code>#define XYZ

class  { };
</code></pre>

<p>This is where C++ compiler complains. It has nothing to do with your file name.</p>

<p>Among C and C++ programmers, it is commonly admitted that header files should be protected by macros named after the file name <strong>including the extension</strong>:</p>

<pre><code>#ifndef XYZ_H
#define XYZ_H
</code></pre>

<p>If you use this practice, you won't have this problem anymore.</p>
