给自己看的,

#include<iostream>
#include <string>
#include <memory>
#include <functional>
#include <regex>
class Quote {
public:
	virtual void sayHello() { std::cout << "Hello from base" << std::endl; }
	virtual void sayHi() { std::cout << "Hi from base" << std::endl; }
	virtual void sayHappy() { std::cout << "Happy from base" << std::endl; }
	void sayHello(int i, int j) { std::cout << "i and j" << std::endl; }
	//std::string isbn() const;
	//virtual double net_price(std::size_t n) const;
};

class DD : public Quote {
public:
	using Quote::sayHello;
	 //implictly overide corresponding virtual functions of base class, though not explicitly them as virtual functions
	void sayHappy(int i) { std::cout << "Happy from derived class" << std::endl; } 
	virtual void sayHello(int i) { std::cout << "Hello from derived class" << std::endl; }
	void sayHi() { std::cout << "Hi from derived class" << std::endl; }
	void sayHello(int i,int j, int h, int k) { std::cout << "I am no-virtual function" << std::endl; }
	
};
class Ddd : public DD {
	virtual void sayHello() { std::cout << "Hello from Ddd class" << std::endl; }

};
class testRvalue {
public:
	void sayVirtual();
	testRvalue(const std::string &sr) : st(sr) { std::cout << "constructing from " << std::endl; }
	testRvalue() {
		std::cout << "default initialization" << std::endl;
	}
	testRvalue(const testRvalue &tr) : st(tr.st) { 
		std::cout << "constructing from copy constructor" << std::endl;
	}
	testRvalue(testRvalue &&tr) :st(std::move(tr.st)) {
		std::cout << "construting from move construtor\n" << "value of the moved form obj" << 
		tr.st << std::endl;
		std::cout << "this value is " << st << std::endl;
	}
private:
	std::string st = "Hello world";


};

class test : public testRvalue {
public:
	test() : j(po()), i(pop()), testRvalue("Hello dda") {}
	static int pop() {
		std::cout << "Hello pop" << std::endl;
		return 0;
	}
	static int po() {
		std::cout << "Hello po" << std::endl;
		return 0;
	}
private:
	int i;
	int j = (pop());
	static int ij;

};
int test::ij = 0;
template <typename T>
bool compare(const T &a, const T &b);
int main() {
	DD *pd;
	pd = new Ddd;
	pd->sayHello();
	test te;
	typedef void (**ppf)(void);
	typedef void(*pf)(void);

	DD dd;
	dd.sayHello();


	int *vTableAddress = (int*)(&dd);
	std::cout << "sizeof vTable" << sizeof(*vTableAddress) << std::endl;

	ppf vTable = ((ppf)(*vTableAddress));
	pf say_hello = *vTable;
	pf say_hi = *(vTable + 1);
	pf say_happy = *(vTable + 2);
	for (int i = 0; i < 10; i++) {
		std::cout << *(vTable + i) << std::endl;
	}
	

	//依次调用 sayHello(), sayHi(), sayHappy()
	say_hello();
	say_hi();
	say_happy();

	

	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值