2014-10-06 11 views
0

, 나는오류 : 예상되는 주요 표현 '('다음 코드에서 토큰

을 얻고 전에
In member function ‘void no_matches::test_method()’: 

error: expected primary-expression before ‘(’ token 

    auto subject = anagram("diaper"); 

코드는 여기 여기

#include "anagram.h" 
#define BOOST_TEST_MAIN 
#include <boost/test/unit_test.hpp> 

using namespace std; 

BOOST_AUTO_TEST_CASE(no_matches) 
{ 
    auto subject = anagram("diaper"); 
    auto matches = subject.matches({"hello", "world", "zombies", "pants"}); 
    vector<string> expected; 

    BOOST_REQUIRE_EQUAL_COLLECTIONS(expected.begin(), expected.end(), matches.begin(), matches.end()); 
}; 

시작 anagram.cpp

#include "anagram.h" 
#include <boost/algorithm/string/case_conv.hpp> 
#include <algorithm> 
#include <cctype> 
using namespace std; 
namespace 
{ 
    string make_key(std::string const& s) 
    { 
     string key{boost::to_lower_copy(s)}; 
     sort(key.begin(), key.end()); 
     return key; 
    } 
} 
namespace anagram 
{ 
    anagram::anagram(string const& subject) 
    : subject_(subject), 
    key_(make_key(subject)) 
{ 
} 
vector<string> anagram::matches(vector<string> const& matches) 
{ 
    vector<string> result; 
    for (string const& s : matches) { 
     if (s.length() == key_.length() 
     && boost::to_lower_copy(s) != boost::to_lower_copy(subject_) 
     && make_key(s) == key_) { 
     result.push_back(s); 
     } 
    } 
    return result; 
} 
} 
입니다

다음은 anagram.h입니다.

#if !defined(ANAGRAM_H) 
#define ANAGRAM_H 
#include <string> 
#include <vector> 
namespace anagram 
{ 
class anagram 
{ 
    public: 
     anagram(std::string const& subject); 
     std::vector<std::string> matches(std::vector<std::string> const& matches); 
    private: 
     std::string const subject_; 
     std::string const key_; 
}; 
} 
#endif 

로컬 컴퓨터에서이 오류를 가져 오지 못했습니다. 나는 https://travis-ci.org으로 건축 할 때만 나는 그것을 얻고있다. 누군가가 버그를 찾도록 도와 줄 수 있습니까?

+2

'anagram' 정의에 대한 코드를 게시 할 수 있습니까? – CoryKramer

+0

클래스 정의 끝에 세미콜론을 잊어 버렸습니다. –

+0

아나그램 정의의 코드는 여기에 있습니다. –

답변

3

namespace anagram (열등한 아이디어 인 IMO)에 class anagram을 넣었으므로 분명히 원하는 이름은 anagram::anagram입니다. 그 자체로 anagram은 네임 스페이스의 이름을 지정합니다. 당신은 하나의 시스템에서 그것을 얻을 것 이유에

auto subject = anagram::anagram("diaper"); 

하지만 다른하지 : 나는 추측에는 요 당신이 일치하지 않는 파일이

그래서, 적어도 첫눈에, 코드가 읽어야 나타납니다 예를 들어 using namespace anagram;이 누락되어 다른 것과 누락되었습니다.

+0

'anagram :: anagram ("diaper");을 할 때 로컬 컴퓨터에서 생성자를 명시 적으로 호출 할 수 없다고 말합니다. 물론 그 코드에는 네임 스페이스가 없습니다. –

+0

네임 스페이스없이'anagram :: anagram'을 사용하려고하면 문제가 될 수 있습니다. 그래서 우리는 실제 문제를 거의 다뤘습니다 : 클래스를 찾기 위해 컴파일러의 이름을 올바르게 지정해야합니다 (두 컴퓨터에서 다른 이름을 가진다면 다른 이름을 * 사용해야한다는 것은 놀라운 일이 아닙니다). 그 기계들). –

+0

좋아, 내가 테스트하고 저녁 식사를하자마자 나는 이것을 정확하게 표시 할 것이다. –