一个神奇的???whatever~~
来源:互联网 发布:女性 音乐家 知乎 编辑:程序博客网 时间:2024/05/16 15:10
一个神奇的类,用来封装消息数据,统一数据传递接口,从unity引擎源码拷贝而来。
#include <iostream>#include <assert.h>#include <crtdefs.h>struct MessageData{int type;private:// Note: on Metro WinRT types cannot be located in union, so don't use union!intptr_t data;public:MessageData (){ data = 0; type = 0; }template<class T>void SetData (T inData, int classId){// Check if SetData is used instead of SetScriptingObjectData //assert (type !=-1);//assert (sizeof (T) > sizeof (data)); // increase the data size*reinterpret_cast<T*> (&data) = *reinterpret_cast<T*> (&inData);type = classId;}template<class T>T GetData (){// Check if GetData is used instead of GetScriptingObjectData assert (type != -1);return *reinterpret_cast<T*> (&data);}intptr_t& GetGenericDataRef (){// Check if GetGenericDataRef is used instead of GetScriptingObjectData assert (type != -1);return data;}};class test{public:test(int x){m_date = x;}void print(){std::cout<<m_date<<std::endl;}private:int m_date ;};int main(){MessageData data;test t(4);data.SetData(&t, 2);test * tt = data.GetData<test*>();tt->print();return 0;}
阅读全文
0 0
- 一个神奇的???whatever~~
- However、Whatever的用法
- whatever
- whatever...
- 一个神奇的shellcode
- 一个神奇的bug
- 一个神奇的博客
- 一个神奇的网站
- 一个神奇的bug
- 一个神奇的函数
- 一个神奇的网站
- 发现一个神奇的东西
- 一个神奇的JS网站
- 一个神奇的Sqrt函数
- c#一个神奇的函数
- 码农是一个神奇的行业
- 飞机票(一个神奇的脚本)
- scanf() 一个神奇的函数
- #leetcode#500 Keyboard Row
- shader
- [提交答案题] UOJ #109 【APIO2013】TASKSAUTHOR
- shader2
- PAT 1001
- 一个神奇的???whatever~~
- PAT 1002
- Build VIM&GVIM Executables on Windows
- leetcode-11. Container With Most Water
- 设计模式之工厂方法模式
- iOS 笔试题02~[有答案]
- c++中测试程序运行时间的方案
- C++静态成员
- golang []byte和string相互转换