Why can't my .cpp file have a class of the same name?
#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.