C4133 In Compatible Types In Assignment Of

and are both arrays, and you cannot assign arrays in C (except when the array is embedded in a structure (or union) and you do a structure assignment).

They are also arrays of pointers to char, rather than pointers to arrays of char. What you have written in the code is probably what you want - you could store pointers to up to MAXINT names in the array. However, you should describe the type correctly - as an array of pointers to char or char pointers.

A pointer to an array of characters would look like:

And a point to an array of character pointers (thanks, Brian) would look like:

Be careful of MAXINT; that could be a very large array (on Linux, defines as , which is at least 231-1).


The code looks like:

Neither the assignment to bar nor car should compile at all - is a . You presumably meant to use in some shape or form. As Brian noted, there are problems there, too:

You either want:

Or you want:

Or, indeed:


Finally, dealing with the array assignment, in C you can reasonably use to do this:

The similar function does not have reliable semantics if the areas to be copied overlap, whereas does; it is simpler to always use because it always works correctly. In C++, you need to be cautious about using (or ). In this code, it would be safe enough, but understanding why is non-trivial.

You do need to be aware that you are just copying pointers here - you are not copying the strings that the pointers point at. If something else changes those strings, it affects both the values seen via and the variable in the calling code.

One last point - for now: are you sure you need the argument to the function as a ? It opens up the code to all sorts of abuse which can be prevented if the function is declared to take a '' instead (or even a '').

Compiler Error C2280

  • 4 minutes to read
  • Contributors

'declaration': attempting to reference a deleted function

The compiler detected an attempt to reference a function. This error can be caused by a call to a member function that has been explicitly marked as in the source code. This error can also be caused by a call to an implicit special member function of a struct or class that is automatically declared and marked as by the compiler. For more information about when the compiler automatically generates or special member functions, see Special member functions.

Example: Explicitly deleted functions

A call to an explicitly function causes this error. An explicitly member function implies that the class or struct is intentionally designed to prevent its use, so to fix this issue, you should change your code to avoid it.

Example: Uninitialized data members

An uninitialized reference type data member or data member causes the compiler to implicitly declare a default constructor. To fix this issue, initialize the data member when it is declared.

Example: Reference and const data members

A or reference type data member causes the compiler to declare a copy assignment operator. Once initialized, these members can't be assigned to, so a simple copy or move can't work. To fix this issue, we recommend you change your logic to remove the assignment operations that cause the error.

Example: Movable deletes implicit copy

If a class declares a move constructor or move assignment operator, but does not explicitly declare a copy constructor, the compiler implicitly declares a copy constructor and defines it as . Similarly, if a class declares a move constructor or move assignment operator, but does not explicitly declare a copy assignment operator, the compiler implicitly declares a copy assignment operator and defines it as . To fix this issue, you must explicitly declare these members.

When you see error C2280 in connection with a , it is almost certainly because you are attempting to invoke its copy constructor, which is a function. By design, a cannot be copied. Use a move constructor to transfer ownership instead.

Example: Variant and volatile members

Versions of the compiler before Visual Studio 2015 Update 2 were non-conforming and generated default constructors and destructors for anonymous unions. These are now implicitly declared as . Those versions also allowed non-conforming implicit definition of copy and move constructors and copy and move assignment operators in classes and structs that have member variables. The compiler now considers these to have non-trivial constructors and assignment operators, and doesn't generate implementations. When such a class is a member of a union, or an anonymous union inside of a class, the copy and move constructors and copy and move assignment operators of the union or class are implicitly defined as . To fix this issue, you must explicitly declare the required special member functions.

Example: Indirect base members deleted

Versions of the compiler before Visual Studio 2015 Update 2 were non-conforming and allowed a derived class to call special member functions of indirectly-derived base classes. The compiler now issues compiler error C2280 when such a call is made.

In this example, class indirectly derives from private virtual . In conforming code, this makes the members of inaccessible to ; an object of type can't be default constructed or destroyed. To fix this issue in code that relied on the old compiler behavior, change the intermediate class to use derivation, or change the class to use direct derivation:

One thought on “C4133 In Compatible Types In Assignment Of

Leave a Reply

Your email address will not be published. Required fields are marked *