C++ 测试 DEMO

#include <iostream>
#include <memory>
#include <atomic>


class C
{
 public:
 	C();
	~C();
 	int my_temp;
 	void test();
 	
};


C::C()
 :my_temp(0)
{
			printf("C构造函数\n");	
			
}


C::~C()
{

}

void C::test()
{
		printf("C::test\n");	

}
namespace metasp
{

	namespace net
	{
		//class C;
		class B	 	 
		 {

			public:
				B(std::shared_ptr<C>tmp,int tmp1);
				virtual ~B();
				
			    virtual void test2()
			    {
			    	printf("virtual void test2\n");
				}
		
			
			    std::shared_ptr<C> pmyC;
			    //std::atomic<int> mytmp1;
			    int  mytmp1;
			    
			    void test3()
			    {
			    	printf("test3()\n");
				}
				
				
	
		
		 };



	} 
}

using namespace metasp::net;
using namespace std;

B::B(std::shared_ptr<C>tmp,int tmp1)
	:pmyC(new C()),
	mytmp1(tmp1)
	{
			printf("B构造函数\n");
			pmyC->test();
			printf("B::mytmp1 = %d\n",(mytmp1));
			printf("B::mytmp1 = %p\n",(&B::mytmp1));//类的偏移地址 
			printf("this->mytmp2 = %d\n",(this->mytmp1));
			test3();
		    this->test3();
		    B::test3();
			
	}



B::~B()
{

}

using NewCallback = std::function<void (int tmp)> ;
using DefaultFunction = std::function<void()>;
class A : public metasp::net::B
{
	
public:
	A(std::shared_ptr<C>tmp,int tmp1);
	~A();
	
	void test2();
	void test2(int a);
	
	void Event1();
	void Event2(int a);
	
	
	
	void setFunc(const DefaultFunction  func);
	void setNewCallback( const NewCallback callback);
//	std::shared_ptr<C> pmyC;
	DefaultFunction messageCallback;
	NewCallback messageCallback1;
	
	
};

A::A(std::shared_ptr<C>tmp,int tmp1)
	:B(tmp,tmp1)
	{
			printf("A构造函数\n");
			pmyC->test();
			
	
			this->setFunc(std::bind(&A::Event1,this));
			this->setNewCallback(std::bind(&A::Event2,this,std::placeholders::_1));
	}

A::~A()
{

}

void A::test2()
{
	printf("A::test2\n");
}

void A::test2(int a)
{
	printf("A::test2(int a) a=%d\n",a);
}



void  A::setNewCallback( const NewCallback callback)
{
    messageCallback1 = callback;
}

void A::setFunc(const DefaultFunction  func)
{
    messageCallback = func;

}

void A::Event1()
{
	printf("A::Event1()\n");
}

void A::Event2(int tmp)
{
	printf("A::Event2() tmp = %d\n",tmp);
}

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	
	std::shared_ptr<C> pmyC;
	int mytmp5 = 5;
	A *pA = new A(pmyC,mytmp5);
	pA->test2();
	pA->test2(7);
	pA->Event1();
	pA->Event2(mytmp5);
	
	printf("hello world\n");
	return 0;
}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值