티스토리 뷰
Reading Books/Effective Series
EC++ Item 9: Never call virtual functions during construction or destruction
DWGoon 2009. 11. 30. 21:25from Effective C++ by Scott Meyers
- Experiments in C++ and Java. Let's compare the results..
- Experiments in C++ and Java. Let's compare the results..
// main.cpp #include <iostream> using namespace std; class Glass { public: Glass() { this->sayHello(); } virtual void sayHello() { cout << "Hello~ I'm a glass." << endl; } }; class WineGlass : public Glass { public: WineGlass() { this->sayHello(); } virtual void sayHello() { cout << "Hello~ I'm a wine glass." << endl; } }; int main() { WineGlass wg; system("pause"); return 0; }
Hello~ I'm a glass.
Hello~ I'm a wine glass.
Hello~ I'm a wine glass.
// Test.java class Glass { { System.out.println("initializing variables of Glass.."); } public Glass() { System.out.println("calling Glass().."); sayHello(); } public void sayHello() { System.out.println("This is a glass."); } } class WineGlass extends Glass { int a; { System.out.println("initializing variables of WineGlass.."); a = 7; } public WineGlass() { System.out.println("calling WineGlass().."); sayHello(); } public void sayHello() { System.out.println("Hello~ This is a wine glass."); System.out.println(""+a); } } public class Test { public static void main(String[] args) { WineGlass wg = new WineGlass(); } }
initializing variables of Glass..
calling Glass()..
Hello~ This is a wine glass.
0
initializing variables of WineGlass..
calling WineGlass()..
Hello~ This is a wine glass.
7
calling Glass()..
Hello~ This is a wine glass.
0
initializing variables of WineGlass..
calling WineGlass()..
Hello~ This is a wine glass.
7
'Reading Books > Effective Series' 카테고리의 다른 글
EC++ Item 25: Consider support for a non-throwing swap (0) | 2009.12.05 |
---|---|
EC++ Item 21: Don't try to return a reference when you must return an object (0) | 2009.12.05 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- volume dial
- structure
- PyQt
- QPrinter.Letter
- how to solve it
- 볼륨 낮춤
- matrix multiplication
- TensorBoard
- GSX 1000 pro
- Python
- MSVC++
- CanDrA
- TCGA
- 볼륨 조절
- pandas
- armadillo c++
- 이상한 문자
- GSX 1200 pro
- destructor
- Item 9
- Visual C++
- tensorflow
- QPrinter.A4
- QT
- cython
- 설치
- dll
- C++
- Accelerated C++
- ctypes
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함