在下面的代碼,我得到錯誤:預期前主表達式 '(' 令牌
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搭建時才能獲得。有人可以幫我找到錯誤嗎?
你可以發佈'anagram'定義的代碼嗎? – CoryKramer 2014-10-06 22:46:36
您在類定義的末尾忘了分號。 – 2014-10-06 22:48:36
anagram定義的代碼在這裏。 – 2014-10-06 23:00:10