@TaeHunKim/

EffectiveCppItem20

C++11

No description

fork
loading
Files
  • main.cpp

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.9779156045319919","path":"main.cpp","file":{"path":"main.cpp","content":{"asEncoding":{"base64":"I2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgV2luZG93IHsKcHVibGljOgoJV2luZG93KCkgPSBkZWZhdWx0OwoJdmlydHVhbCB2b2lkIGRpc3BsYXkoKSBjb25zdCB7CgkJc3RkOjpjb3V0IDw8ICJ3aW5kb3ciPDwgc3RkOjplbmRsOwoJfSAvLyBkcmF3IHdpbmRvdyBhbmQgY29udGVudHMKfTsKY2xhc3MgV2luZG93V2l0aFNjcm9sbEJhcnMgOiBwdWJsaWMgV2luZG93IHsKcHVibGljOgoJV2luZG93V2l0aFNjcm9sbEJhcnMoKSA9IGRlZmF1bHQ7Cgl2aXJ0dWFsIHZvaWQgZGlzcGxheSgpIGNvbnN0IHsKCQlzdGQ6OmNvdXQgPDwgIndpbmRvd1dpdGhTY3JvbGxCYXJzIiA8PCBzdGQ6OmVuZGw7Cgl9Cn07Cgp2b2lkIHByaW50TmFtZUFuZERpc3BsYXkoV2luZG93IHcpIC8vIGluY29ycmVjdCEgcGFyYW1ldGVyCnsJCQkJCQkJCSAgIC8vIG1heSBiZSBzbGljZWQhCgl3LmRpc3BsYXkoKTsKfQp2b2lkIHByaW50TmFtZUFuZERpc3BsYXlBc1JlZihjb25zdCBXaW5kb3cmIHcpIC8vIGZpbmUsIHBhcmFtZXRlciB3b27igJl0CnsgLy8gYmUgc2xpY2VkCiAgdy5kaXNwbGF5KCk7Cn0KaW50IG1haW4oKSB7CglXaW5kb3dXaXRoU2Nyb2xsQmFycyB3d3NiOwoJcHJpbnROYW1lQW5kRGlzcGxheSh3d3NiKTsKCXByaW50TmFtZUFuZERpc3BsYXlBc1JlZih3d3NiKTsKfQ=="},"asBuffer":null},"loaded":true}}
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
#include <iostream>

class Window {
public:
	Window() = default;
	virtual void display() const {
		std::cout << "window"<< std::endl;
	} // draw window and contents
};
class WindowWithScrollBars : public Window {
public:
	WindowWithScrollBars() = default;
	virtual void display() const {
		std::cout << "windowWithScrollBars" << std::endl;
	}
};

void printNameAndDisplay(Window w) // incorrect! parameter
{								   // may be sliced!
	w.display();
}
void printNameAndDisplayAsRef(const Window& w) // fine, parameter won’t
{ // be sliced
  w.display();
}
int main() {
	WindowWithScrollBars wwsb;
	printNameAndDisplay(wwsb);
	printNameAndDisplayAsRef(wwsb);
}