Hiding constructior is required while no direct invocation to it with G++ 4

corey taylor corey.taylor@gmail.com
Thu Sep 28 05:28:00 GMT 2006


What are you trying to do here?  If you still want a copy made, why
are you trying to hide the copy constructor?

corey

On 9/27/06, Yuanfei guo <yuanfei8077@gmail.com> wrote:
> Hi there,
>
>
>
> I found that the compiling the following code will fail with g++ 4.1
> while cmopile succeed with VC8.  Any comments/suggestions is highly
> appreciated.
>
>  env info
> =========
> g++ (GCC) 4.1.0  (SLES10)
>
> No compile option is added
>
>
> Compilation error
>
> =================
> main.cpp: In copy constructor MemAllocator<int>::MemAllocator(const
> MemAllocator<int>&)
> main.cpp:5: error: MemPool::MemPool(const MemPool&) is protected
> main.cpp:8: error: within this context
> main.cpp: In function int main()
> main.cpp:32: note: synthesized method
> MemAllocator<int>::MemAllocator(const MemAllocator<int>&) first
> required here
>
>
>
> Repro code
> ===========
> class MemPool {
> public:
>        MemPool(){};
> protected:
>        MemPool(const MemPool& mempool);
> };
>
> template <class Type> class MemAllocator{
> public:
>        MemPool m_pool;
>        MemAllocator(){}
>        MemPool& get_pool() const {
>                return m_pool;
>        }
>        template<class OtherType>
>        MemAllocator<Type>& operator=(const MemAllocator<OtherType>& rhs){
>                m_pool = rhs.get_pool;
>                return *this;
>        }
> };
>
>
> template <class _AllocType> class tdat_hash_map {
> public:
>        typedef _AllocType _Alloc;
>        static void func(_Alloc&) {};
> };
>
> int main()
> {
>        typedef tdat_hash_map<MemAllocator<int> > Map;
>        MemAllocator<int> abc = MemAllocator<int>();
>
>        return 0;
> }
>
>
>
>
> Thanks,
> -Kelvin
>



More information about the Gcc-help mailing list