티스토리 뷰
테스트 코드
// Has been tested with Dev-C++(GCC 4.X) #include <cstdlib> #include <iostream> #include <string> using namespace std; class BaseClass { public: string name; virtual void print() { cout << name << endl; } }; class Class : public BaseClass { public: string familyName; void print() { cout << name << " " << familyName<< endl; } }; int main(int argc, char *argv[]) { const int numElem = 3; Class clsArray[3]; clsArray[0].name = "David"; clsArray[0].familyName = "Robinson"; clsArray[1].name = "Daewon"; clsArray[1].familyName = "Lee"; clsArray[2].name = "Charlie"; clsArray[2].familyName = "Chaplin"; BaseClass* bsClsArray = clsArray; // Runtime error occurs after processing first element of bsClsArray, // because bsClsArray[i] is performed with bsClsArray + sizeof(BaseClass) // not with bsClsArray + sizeof(Class) // We can get fine result by replacing BaseClass* with Class* // in declaration of bsClsArray system("PAUSE"); return EXIT_SUCCESS; }
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- matrix multiplication
- 볼륨 낮춤
- destructor
- armadillo c++
- GSX 1200 pro
- 볼륨 조절
- Python
- QPrinter.A4
- Item 9
- Accelerated C++
- structure
- cython
- how to solve it
- GSX 1000 pro
- Visual C++
- PyQt
- 설치
- volume dial
- pandas
- MSVC++
- ctypes
- dll
- CanDrA
- TCGA
- C++
- TensorBoard
- QT
- QPrinter.Letter
- tensorflow
- 이상한 문자
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함