📄 main.cpp
字号:
#include <iostream>
#include <stdlib.h>
#include <string>
#include <typeinfo>
using namespace std;
class King {
protected:
string CrownName;
public:
virtual string &MyName() { return CrownName; }
King(King &) { cout << "Converting!" << endl; }
King(King *) { cout << "Converting!" << endl; }
King() { cout << "Creating!" << endl; }
};
class Prince : public King {
public:
string School;
};
class FinalType {};
class AnotherType : public FinalType {};
void DumpItems(void *buffer, int size) {
int loop;
char *str = (char *)buffer;
cout << "Dumping " << size << " bytes." << endl;
for (loop = 0; loop < size; loop++) {
cout << (int)str[loop] << endl;
}
}
int main(int argc, char *argv[])
{
Prince George;
George.MyName() = "George I";
George.School = "School of the Kings";
King *asKing = static_cast<King *>(&George);
//int x = 10;
//float f = static_cast<float>(x);
//AnotherType *orig = new AnotherType;
//FinalType *f = static_cast<FinalType *>(orig);
//cout << f << endl;
char *str = "abc";
long int nums[] = {1,2,3,4,5};
DumpItems(str, sizeof(str));
DumpItems(nums, sizeof(nums));
system("PAUSE");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -