代码拉取完成,页面将自动刷新
//
// Created by lmy on 2024/11/14.
//
#include <iostream>
#include "ClassTest.h"
using namespace std;
class Blank {
enum {
age_bits = 4,
lock_bits = 2,
biased_lock_bits = 1,
};
public:
Blank() {
age_bits;
cout << "Blank---" << endl;
}
};
class Animal {
public:
int color;
int age;
string name;
// Blank blank;
Animal() {
cout << "创建---->Animal:" << "name:" << name.capacity() << endl;
}
Animal(const Animal &g) {
cout << "拷贝/复制函数---->Animal 参数地址:" << &g << endl;
cout << "拷贝/复制函数---->Animal this地址:" << this << endl;
}
Animal &operator=(const Animal &g) {
cout << "赋值---->Animal" << &color << endl;
}
void *operator new(size_t size) // 参数必须是size_t(unsigned long long),返回值必须是void*。
{
cout << "调用了类的重载的new:" << size << "字节。\n";
void *ptr = malloc(size); // 申请内存。
cout << "申请到的内存的地址是:" << ptr << endl;
return ptr;
}
void operator()(string str) // 向超女表白的函数。
{
cout << "重载函数:" << str << endl;
}
Animal operator++(int) // ++后置的重载函数。
{
Animal tmp = *this;
age++;
cout << "++后置的重载函数 Animal: color," << color << "---" << this << endl;
return tmp;
}
Animal operator++() // ++前置的重载函数。
{
age++;
cout << "++前置的重载函数 Animal: color," << color << endl;
return *this;
}
~Animal() {
cout << "销毁---->Animal: color," << color << endl;
}
int getColor() {
return color;
}
int getAge() {
return age;
}
};
class Cat : public Animal {
public:
Cat() {
cout << "Cat" << endl;
}
void getInfo() {
cout << color << this->getAge() << endl;
}
};
void getA(Animal a1) {
cout << "getA:" << &a1 << endl;
}
int main() {
// Cat cat;
// cat.getInfo();
// cout << "main" << sizeof cat << sizeof(Animal) << endl;
// Animal a, b;
// cout << "a:" << &a << ",b:" << &b << endl;
// a.color = 10;
// b.color = 20;
// b = a;
// cout << "a:" << &a << ",b:" << &b << endl;
// Animal d;
// cout << "cd:" << &d << endl;
//
// Animal c = d;
// cout << "c:" << &c << endl;
// // getA(c);
// Animal *e = new Animal();
// Animal f;
// f("xxxxx");
// (*e)("x2");
Animal g;
++g;
// cout << "g age:" << g.age << endl;
//
// cout << "g:" << &g << endl;
//
// Animal h= ++g;
// cout << "h:" <<h.age << endl;
// Animal l = g++;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。