This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]