YangH
YangH

Reputation: 57

boost::pool error C2248

#define BOOSTPOOL boost::pool<>
BOOSTPOOL GetPool()
{
    BOOSTPOOL AppClass1Pool(sizeof(AppClass1));
    return AppClass1Pool;
}

void* AppClass1::operator new(size_t sz)
{
    BOOSTPOOL temp = GetPool();
    void* p =(void*) temp.malloc();
    return p;
}

can not access to the private member(in “boost::simple_segregated_storage<SizeType>”) I can not use pool like this?

Upvotes: 1

Views: 181

Answers (1)

sehe
sehe

Reputation: 392833

I don't see what you are trying to do with the code shown.

Also, chances are that the error originates in the code you don't show, but here's my 5p:

Pools are non-copyable. I assume, under C++03 you get can not access to the private member because the copy constructor is private. In c++11 you can expect:

error: use of deleted function ‘boost::pool<>::pool(const boost::pool<>&)’

Here is a fixed-up version that probably does what you intended:

// Uncomment this to stub out all MT locking
// #define BOOST_NO_MT

#include <boost/pool/pool.hpp>

struct AppClass1
{
    int data[10];
    void* operator new(size_t sz);
};

#define BOOSTPOOL boost::pool<>
BOOSTPOOL& GetPool()
{
    static BOOSTPOOL AppClass1Pool(sizeof(AppClass1));
    return AppClass1Pool;
}

void* AppClass1::operator new(size_t sz)
{
    BOOSTPOOL& temp = GetPool();
    void* p =(void*) temp.malloc();
    return p;
}

int main(int argc, const char *argv[])
{
    return 0;
}

Upvotes: 1

Related Questions