I am very new to programming, and am using C++.
in my header file : Globals.h, I have declared both my enum, "Colour" and a function meant to test it.
In my source file, Globals.cpp, I have defined both the enum and the test function.
In main I call the function but am given this message:
Error C2027: Use of undefined type 'Colour'
and
Error C2065: 'COLOUR_BLACK': Undeclared identifier.
My code is below:
Globals.h
#ifndef GlOBALS_H
#define GLOBALS_H
enum class Colour;
void print_Colour(Colour whatColour);
#endif
and:
Globals.cpp
#include <iostream>
#include "Globals.h"
enum class Colour
{
COLOUR_BLACK,
COLOUR_BROWN,
COLOUR_BLUE,
COLOUR_GREEN,
COLOUR_RED,
COLOUR_YELLOW
};
void print_Colour(Colour whatColour)
{
switch (whatColour)
{
case Colour::COLOUR_BLACK:
std::cout << "Black" << "\n";
break;
case Colour::COLOUR_BROWN:
std::cout << "Brown" << "\n";
break;
case Colour::COLOUR_BLUE:
std::cout << "Blue" << "\n";
break;
case Colour::COLOUR_GREEN:
std::cout << "Green" << "\n";
break;
case Colour::COLOUR_RED:
std::cout << "Red" << "\n";
break;
case Colour::COLOUR_YELLOW:
std::cout << "Yellow" << "\n";
break;
default:
std::cout << "Who knows!" << "\n";
}
}
and:
Source.cpp
#include <iostream>
#include "Globals.h"
using namespace std;
int main()
{
Colour paint = Colour::COLOUR_BLACK;
print_Colour(paint);
std::cin.get();
std::cin.get();
return 0;
};
Any help would be greatly appreciated!