title: Cross type casting operator in C++
body: <p>I have two classes A and B, and my C++ code is as follows:</p>
  
  <pre><code>class A
  {
  int k;
  public:
      //Some functions
      operator B()
      {
          B alpha;
          alpha.x=k;
          alpha.y=0;
          return alpha;
      }
  };
  
  class B
  {
  int x,y;
  public:
      //Some functions
      operator A()
      {
          A play;
          play.k=x;
          return play;
      }
  };
  </code></pre>
  
  <p>However, I am facing a problem while executing this (I have written proper main). It shows an error message: <strong><em>Expected type-specifier before B</em></strong></p>
  
  <p>I thought that the problem is due to placing class A before B. However, when I channged that, i.e. put class B before A, the same type of error message appears:<strong><em>Expected type-specifier before A</em></strong></p>
  
  <p>How do I solve this problem (I mean please suggest changes in the code so that it works)? I need to use cross type casting in my work.</p>
  
  <p><em>(I have tried it with two compilers, Code::Blocks (13.12) and MinGW (w64). But same message is being shown in both cases)</em></p>