2011-11-27 44 views
1
#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; 
} 

無法訪問(在「boost::simple_segregated_storage<SizeType>」) 私有成員,我無法使用游泳池這樣嗎?的boost ::池錯誤C2248

回答

1

我沒有看到你正在試圖做的代碼顯示。

而且,機會是錯誤的,你不顯示的代碼起源,但這裏是我的5P:

池是不可複製的。我假設,在C++ 03下,你得到了can not access to the private member,因爲拷貝構造函數是私有的。在C++ 11,你可以期望:

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

這裏是一個固定的後續版本,可能做你的原意:

// 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; 
} 
+0

謝謝,我已經在你的幫助解決了這個問題。 – YangH