In the following example, I have an object class which defines a reference class. Both accept mutability as a template argument. In the case that 'obj' is 'Const', I want to disallow a reference of type 'Non_Const'. The example produces the ambiguous message, "An internal error has occurred in the compiler," in Visual C++ 2012. Should this compile? If not, why, and is there another way to accomplish the same thing?
enum Mutability {Const, Non_Const};
template <typename T, Mutability U>
class Obj
{
public:
template <Mutability V>
class Ref
{
public:
Ref() {}
friend class Obj;
};
Obj() {}
};
template <typename T>
class Obj<T, Const>::template Ref<Non_Const>
{
private:
Ref() {}
}; //error C1001: An internal error has occurred in the compiler
int main()
{
Obj<int, Const>::Ref<Non_Const> test;
}