小编Ale*_* B.的帖子

使用Boost.Spirit.Lex和流迭代器

我想用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)

c++ boost boost-spirit c++11

5
推荐指数
1
解决办法
533
查看次数

为什么shared_ptr <T>期望在T中复制/移动构造函数?

我有以下代码:

#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)

c++ templates copy-constructor shared-ptr c++11

0
推荐指数
1
解决办法
577
查看次数