📄 derived.cpp
字号:
// claa.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class Base {
public:
Base(int value=0):x(value) {}
virtual ~Base() {}
Base(const Base& rhs):x(rhs.x) {}
Base& operator =(const Base& rhs){x=rhs.x; return *this;}
private:
int x;
};
class Derived:public Base {
public: Derived(int v):Base(v),y(v) { }
virtual ~Derived() {}
Derived(const Derived& rhs);
Derived& operator=(const Derived& rhs);
private:
int y;
};
Derived& Derived::operator=(const Derived& rhs)
{
if (this == &rhs) return *this;
static_cast<Base&>(*this) = rhs; // 对*this的Base部分调用operator=
y = rhs.y;
return *this;
}
Derived::Derived(const Derived& rhs)
{
*this =rhs;
}
int main(int argc, char* argv[])
{
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -