Lord Zoltan

Hi everyone,

Anyone know how to inhibit the compiler's autogeneration of copy constructors and equals operators for classes other than defining your own

I have a template queue class for which cloning is not really a valid operation, and as such some of it's nested types are not suitable for auto-generated copy constructors/operators.

Because of this, when I compile some code that uses the outer template class, I get compiler errors such as:

error C2678: binary '=' : no operator found which takes a left-hand operand of type 'volatile T<itemtype>::NestedType' (or there is no acceptable conversion)

When I double-click on the error, the editor simply goes to the end of the class declaration that has declared a member of type T<sometype>.

Further investigation down the error list yields:

This diagnostic occurred in the compiler generated function T<itemtype> &T<itemtype>::operator =(const T<itemtype> &)'.

I can fix the error by defining a dummy copy constructor that is a clone of my default constructor, but I feel that misleads programmers using the class into thinking they can clone an instance of that type.

Is there anything else I can do



Re: Visual C++ Language Autogenerated copy constructors and equals operators

einaros

Lord Zoltan wrote:

Anyone know how to inhibit the compiler's autogeneration of copy constructors and equals operators for classes other than defining your own

Declaring (not defining) a private copy ctor and assignment operator is common practice to avoid copying classes which shouldn't be copied. Boost's noncopyable is one base class which enforces this principle.






Re: Visual C++ Language Autogenerated copy constructors and equals operators

Lord Zoltan

Okay, thanks.

Stupidly enough I hadn't thought of making them private. You know how sometimes you can become codeblind I think I need a break!

Cheers