2014-11-24 3 views
0

내 컴파일러는 모든 컨트롤 경로가 값을 반환하지 않으며 오버로드 된 >> 변수 함수를 가리킨다 고 말합니다. 나는 정확히 무엇이 문제를 일으키는 지 잘 모르겠다. 그리고 어떤 도움도 인정 될 것이다. 입력이 유효한 지 정의하기 위해 스트림 추출 연산자를 오버로드하려고합니다. 그렇지 않으면 부적절한 입력을 나타내는 failbit을 설정해야합니다.모든 컨트롤 경로가 값을 반환하지 않습니다.

std::istream &operator >> (std::istream &input, ComplexClass &c)//overloading  extraction operator 
    { 
     int number; 
     int multiplier; 
     char temp;//temp variable used to store input 


     input >> number;//gets real number 

     // test if character is a space 
     if (input.peek() == ' ' /* Write a call to the peek member function to 
           test if the next character is a space ' ' */) // case a + bi 
     { 
      c.real = number; 
      input >> temp; 

      multiplier = (temp == '+') ? 1 : -1; 
     } 
      // set failbit if character not a space 
     if (input.peek() != ' ') 
     { 
      /* Write a call to the clear member function with 
      ios::failbit as the argument to set input's fail bit */ 
      input.clear(ios::failbit); 
     } 
     else 

       // set imaginary part if data is valid 
      if (input.peek() == ' ') 
      { 
       input >> c.imaginary; 
       c.imaginary *= multiplier; 
       input >> temp; 
      } 
      if (input.peek() == '\n' /* Write a call to member function peek to test if the next 
               character is a newline \n */) // character not a newline 
      { 
       input.clear(ios::failbit); // set bad bit 
      } // end if 
      else 
      { 
        input.clear(ios::failbit); // set bad bit 
      } // end else 
      // end if 
     if (input.peek() == 'i' /* Write a call to member function peek to test if 
             the next character is 'i' */) // test for i of   imaginary number 
     { 
      input >> temp; 

      // test for newline character entered 
      if (input.peek() == '\n') 
      { 
       c.real = 0; 
       c.imaginary = number; 
      } // end if 

      else if (input.peek() == '\n') // set real number if it is valid 
      { 
       c.real = number; 
       c.imaginary = 0; 
      } // end else if 
      else 
      { 
       input.clear(ios::failbit); // set bad bit 

      } 


      return input; 
     } 
    } 

답변

0

return 문은 내부에서 실행되는 마지막 경우 :

if (input.peek() == 'i') { 
    ... 
} 
return input; 
:

if (input.peek() == 'i') { 
    ... 
    return input; 
} 

은 변경해야

관련 문제