-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathItem5.cpp
More file actions
37 lines (30 loc) · 708 Bytes
/
Item5.cpp
File metadata and controls
37 lines (30 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// This program won't compile. Look below for details.
#include <iostream>
using namespace std;
class Stub
{
public:
int& iVar;
Stub(int i);
// Stub& operator = ( const Stub& rhs);
};
Stub::Stub(int i): iVar(i) { }
/*Stub& Stub::operator = (const Stub& rhs)
{
this->iVar = rhs.iVar;
return *this;
}
*/
int main()
{
int a = 10, b = 20;
Stub s2(a);
Stub s1(b);
/* C++ is unsure how to generate an implicit assignment operator without
* being illegal or nonsense. Its illegal when:
* a). Classes contain reference members
* b). Classes contain const members
* c). in derived classes that inherit from base classes declaring the copy assignment operator private.
*/
s1 = s2;
}