I have an enumeration data type as follows: enum class CellColor {white, black};
.
I need to write a public member function that shall be named get_color
and shall return type CellColor
and shall accept no input parameters. This function will also return the value of Cell
's color
member.
I've tried writing it out dozens of times, but I am still encountering errors.
Here is what I have so far:
#ifndef HAVEYOUSEENTHSISNAIL_CELL
#define HAVEYOUSEENTHSISNAIL_CELL
#include "definitions.hpp"
#include <iostream>
class Cell { // This class is used to define the NxN board in the final solution.
public:
Cell() { // DEFAULT CONSTRUCTOR
enum CellColor {white, black};
CellColor color = white; // Shall set color to white upon construction
}
void change_color() { // PUBLIC MEMBER FUNCTION FOR COLOR CHANGE
enum CellColor {white, black};
CellColor color;
if (color == white) {
color = black;
}
else if (color == black) {
color = white;
}
return; // Return type void & accepts no parameters
}
CellColor get_color() { // PUBLIC MEMBER FUNCTION FOR CURRENT COLOR
enum CellColor {white, black};
CellColor color;
return color;
// Shall return type CellColor
// Shall return the value of the Cell's Color member
}
std::string get_color_string() { // PUBLIC MEMBER FUNCTION FOR CURRENT COLOR STRING
enum CellColor {white, black};
CellColor color;
if (color == black) {
std::string black = "1";
return black; // Returns type std::string
}
else if (color == white) {
std::string white = "0";
return white; // Returns type std::string
}
}
private:
enum class CellColor {white, black}; // Scoped enum: enum [class] [structure] {enum list};
CellColor color; // Creating CellColor type variable color
};
#endif
Any suggestions on how to write an enum
type function that also returns an enum
type?