我想用Boost.Spirit.Lex来表示二进制文件; 为此我编写了以下程序(这是一个摘录):
#include <boost/spirit/include/lex_lexertl.hpp>
#include <boost/spirit/include/support_multi_pass.hpp>
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#include <fstream>
#include <iterator>
#include <string>
namespace spirit = boost::spirit;
namespace lex = spirit::lex;
#define X 1
#define Y 2
#define Z 3
template<typename L>
class word_count_tokens : public lex::lexer<L>
{
public:
word_count_tokens () {
this->self.add
("[^ \t\n]+", X)
("\n", Y)
(".", Z);
}
};
class counter
{
public:
typedef bool result_type;
template<typename T>
bool operator () (const T &t, size_t &c, size_t &w, size_t &l) const {
switch (t.id …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
#include <memory>
using namespace std;
template<typename U> class A;
template<typename U>
class B
{
private:
shared_ptr<const A<U>> _a;
public:
B (shared_ptr<const A<U>> __a) {
_a = __a;
}
};
template<typename U>
class A
{
public:
B<U> foo () const {
return { make_shared<const A<U>> (this) };
}
};
int
main ()
{
A<int> a;
B<int> b = a.foo ();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
G ++ 4.8.0和Clang 3.3svn报告该类A没有复制或移动构造函数.例如,G ++打印以下消息:
/home/alessio/Programmi/GCC/include/c++/4.8.0/ext/new_allocator.h:120:4: error: no matching function for call to ‘A<int>::A(const A<int>* …Run Code Online (Sandbox Code Playgroud)