This is my main file:
#include "MyHeader.h"
int main(void)
{
MyClass Test1;
Test1.set_a_thing();
return 0;
}
This is the Header file:
#ifndef MY_CLASS_H_
#define MY_CLASS_H_
class MyClass
{
public:
MyClass();
~MyClass();
enum A_few_Things { yes, no, sometimes, dont_know };
enum MyClass::A_few_Things set_a_thing();
private:
A_few_Things a_few_things = A_few_Things::dont_know;
};
#endif // !MY_CLASS_H_
And this is the related cpp file:
#include "MyHeader.h"
MyClass::MyClass()
{
}
MyClass::~MyClass()
{
}
MyClass::A_few_Things MyClass::set_a_thing()
{
// for example, return Yes
return A_few_Things::yes;
}
The line enum A_few_Things { yes, no, sometimes, dont_know };
seems to have to be public. If it is in the private:
field, there is an error message:
E0471 class " * " does not have an identifier with the name " * "
How can you ensure that the enum
itself cannot be called from Main.cpp
, but that only the function set_a_thing()
– which is called from Main.cpp
– sees and handles it?
Is there a special keyword?
For example, I want the function set_a_thing
to return yes
.
I'm fairly new to C++. My only concern is that I want to learn it right from the start. When you say there is no need to do it differently, so then...