Q:

How to make conversion operator returning reference and non reference

I have a template class, looking something like:
template<class T>
class A
{
  public:
     operator T() const {  return value;}
     operator T&() { return value;}

  private:
       T value;

}

It seems that the operatorT() const is never called. Even in a statement like this
const int a = myA;

where myA is a  instance of A.
Is there something wrong, missing  with the above code?

A:

The operator will take effect only when you define an object of type const A<T>. For example:
const A<int> myA;
int someInt = myA;

will call operator T() const.
And, since it's of course true - like Benjamin Lindley pointed out - if you access the object through a const reference.

