2012-12-04 2 views
0

나는이 컴파일 할 때 나는 이상한 오류를 받고 있어요 :왜 컴파일되지 않습니까? 아무 짝 '연산자 & ='

C:\Users\Usuario\Desktop\Temp\C++\tc.cpp: In member function `std::string CucumberMarket::check(std::vector<int, std::allocator<int> >, int, int)': 
C:\Users\Usuario\Desktop\Temp\C++\tc.cpp:24: error: no match for 'operator&=' in '((CucumberMarket*)this)->CucumberMarket::ans &= CucumberMarket::check(std::vector<int, std::allocator<int> >, int, int)(vector<int,std::allocator<int> >(((const std::vector<int, std::allocator<int> >&)((const std::vector<int, std::allocator<int> >*)(&price)))), (&price)->std::vector<_Tp, _Alloc>::operator[] [with _Tp = int, _Alloc = std::allocator<int>](((unsigned int)i)), i)' 
[Finished in 0.2s with exit code 1] 

라인 (24)은 이것이다 :

class CucumberMarket { 
public: 
    bool ans; 
    int n,cont,K,b; 
    bool check(const vector<int> &precios,long long price,int pos) { 
    ++cont; 
    if(cont == K and b < price) ans = false; 
    if(!ans) return ans; 
    for(int i = pos + 1; i < n; ++i) { 
     if(cont < K) ans &= check(precios,price + precios[i],i); 
    } 
    --cont; 
    } 
    string check(vector <int> price, int budget, int k) { 
    n = price.size(); 
    K = k; 
    b = budget; 
    ans = true; 
    cont = 0; 
    for(int i = 0; i < n and ans; ++i) ans &= (this -> check(price,price[i],i)); 
    return ans ? "YES" : "NO"; 
    } 
}; 

이 내가 갖는 것입니다 :

for(int i = 0; i < n and ans; ++i) ans &= (this -> check(price,price[i],i)); 

나는 그것을 얻지 못하는 이유는 무엇입니까? 나는 전에 이것을했고 항상 컴파일되었습니다.

+2

오른쪽 부울식이 필요합니다. 두 번째 오버로드를 호출하여 문자열을 반환합니다. – chris

답변

7

std::string CucumberMarket::check 수표가 string을 반환한다고 가정합니다. 이것은 귀하의 문제이며, 당신은 bool을 돌려받을 것으로 예상됩니다. 당신이 제대로 작동하려면
는 간단한 수정은 내가 당신의 과부하를 추천 할 것입니다 for(int i = 0; i < n and ans; ++i) ans &= (this -> check(price,(long long)price[i],i));

아래로 long long에 캐스팅 price[i]을 강제하는 것입니다 그래서 현명한 서명 가깝게 할 수니까. 귀하의 오류 메시지에서

+0

고마워, 내가 방금 한 바보 같은 실수. – hinafu

+0

당신은 오신 것을 환영합니다! –

2

봐 : 그것은

ans &= check(..., int, int) 

하려고 그리고 검사의 버전 문자열을 반환합니다. &=

관련 문제