The std::vector is easy, it can become just vector by:
usingnamespace std;
or
using std::vector;
but I was wondering whether there is a way to do the same for Cube::. I have tried various arrangements of the keyword "using" with Cube, but the problem is that Cube is a class. Cube::Face and Cube::Direction are enums declared in Cube.
e.g.
1 2 3 4 5
class Cube
{
enum Face {f_TOP, f_LEFT...}
enum Direction {d_LEFT, d_UP...}
};
Is there some way to neaten up the first example code using typedefs or the using keyword (or any other way)?
If Cube is a namespace, you can just do the same as you would for std
1 2 3 4 5 6 7 8 9
namespace Cube
{
enum Face {f_TOP, f_LEFT, r_TOP};
enum Direction {d_LEFT, d_UP, d_RIGHT};
};
//in your code or main
usingnamespace Cube;
cout<<r_TOP<<d_RIGHT<<d_LEFT<<endl;
You cannot use the scope resolution operator on a enumeration. This is because enumerations are not scoped types. Some compilers will allow this behaviour, but only as a non-standard extension. However, in C++11, enum class was introduced which allows the scoping of enumerators, as well as the ability to choose the underlying type of the enumerators.
An alternative to this is using the namespace - therockon7throw has already suggested this. However, I don't recommend uses classes, because namespaces are more suited for the job.