Skip to content

Commit 7f7c8e8

Browse files
author
Colin Robertson
committed
More C2280 fixes per review.
1 parent 6fc9ea1 commit 7f7c8e8

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

‎docs/error-messages/compiler-errors-1/compiler-error-c2280.md‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,21 @@ struct A {
8282

8383
## Example: Reference and const data members
8484

85-
A `const` or reference type data member causes the compiler to declare a `deleted` copy constructor and assignment operator. To fix this issue, explicitly declare the required functions.
85+
A `const` or reference type data member causes the compiler to declare a `deleted` copy assignment operator. Once initialized, these members can't be assigned to. To fix this issue, we recommend you change your logic to remove the copy assignment operations that cause the error.
8686

8787
```cpp
8888
// C2280_ref.cpp
8989
// compile with: cl /c C2280_ref.cpp
90-
int k = 42;
90+
extern int k;
9191
struct A {
9292
A();
93-
int& ri = k; // reference data member
94-
// causes implicit assignment operator to be deleted.
95-
// To fix, declare it explicitly:
96-
// A& operator=(const A& ra) { this->ri = ra.ri; return *this; };
93+
int& ri = k; // a const or reference data member causes
94+
// implicit copy assignment operator to be deleted.
9795
};
9896

9997
void f() {
10098
A a1, a2;
99+
// To fix, consider removing this assignment.
101100
a2 = a1; // C2280
102101
}
103102
```
@@ -164,7 +163,7 @@ int main() {
164163
165164
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 `private virtual` base classes. The compiler now issues compiler error C2280 when such a call is made.
166165
167-
In this example, class `top` indirectly derives from private virtual `base`. In conforming code, this makes the members of `base` inaccessible to `top`; an object of type `top` can't be instantiated or destroyed. To fix this issue in code that relied on the old compiler behavior, change the intermediate class to use `protected virtual` derivation, or change the `top` class to use direct derivation:
166+
In this example, class `top` indirectly derives from private virtual `base`. In conforming code, this makes the members of `base` inaccessible to `top`; an object of type `top` 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 `protected virtual` derivation, or change the `top` class to use direct derivation:
168167
169168
```cpp
170169
// C2280_indirect.cpp

0 commit comments

Comments
 (0)