如何实现一个C++反射库
答案:2 悬赏:80 手机版
解决时间 2021-04-08 00:33
- 提问者网友:锁深秋
- 2021-04-07 09:11
如何实现一个C++反射库
最佳答案
- 五星知识达人网友:轻熟杀无赦
- 2021-04-07 09:41
如果你用的是Visual Studio的话,你可以在安装目录下搜到一个dia100.dll/dia110.dll/dia120.dll,这个库可以用来读pdb文件。你只要稍微研究一下就可以拿到编译的时候生成的类型信息了。然后你根据这些信息再codegen出一份代码,合并进去编译。debug的时候随便搞,你在写release脚本的时候只要编译你的程序两遍就可以得到反射了。
这是所有已知的方法里面最容易完成的。下面的博客里面提到的PdbDump的代码你可以在我的www.gaclib.net 的代码gac.codeplex.com 下找到,名字一样,下载下来搜一下就有了。
这是所有已知的方法里面最容易完成的。下面的博客里面提到的PdbDump的代码你可以在我的www.gaclib.net 的代码gac.codeplex.com 下找到,名字一样,下载下来搜一下就有了。
全部回答
- 1楼网友:拜訪者
- 2021-04-07 10:01
//c++源代码
//绕原点旋转角度无法确定旋转的方向,因而不能确定参量的输入
//所以只实现了绕x,y,z轴旋转
//---------------------------------------------------------------------------
#include
#include
#pragma hdrstop
//---------------------------------------------------------------------------
class vetor
{
public:
vetor(void):x(0),y(0),z(0){}
vetor(double dx, double dy, double dz):x(dx),y(dy),z(dz){}
vetor(double dd):x(dd),y(dd),z(dd){}
vetor(vetor& a):x(a.x),y(a.y),z(a.z){}
~vetor(){}
void rotate(char, double);
//旋转: 1-绕x轴, 2-绕y轴, 3-绕z轴;旋转角(角度)
//右手螺旋法则为角度正方向
double abs(void);//取向量模
void display(void);//显示向量
vetor& operator++(void)
{ this->x++;this->y++;this->z++;
return (*this);
}
vetor& operator--(void)
{ this->x--;this->y--;this->z--;
return (*this);
}
vetor operator++(int a)
{ vetor temp(*this);
++*this;
return temp;
}
vetor operator--(int a)
{ vetor temp(*this);
--*this;
return temp;
}
friend vetor operator+(vetor, vetor);
friend vetor operator-(vetor, vetor);
private:
double x,y,z;
};
#pragma argsused
int main(int argc, char* argv[])
{
vetor test ;
double x,y,z,c,a;
cout<<"please input (x,y,z) in order(seperated by space): ";
cin>>x>>y>>z;
test = vetor(x,y,z);
test.display();
cout<<"菜单:"<>c>>a;
test.rotate(c,a);
test.display();
system("pause");
return 0;
}
//---------------------------------------------------------------------------
void vetor::rotate(char choice, double theta)
//旋转: 1-绕x轴, 2-绕y轴, 3-绕z轴; 旋转角theta(角度)
//右手螺旋法则为角度正方向
{
double xp,yp,zp;
theta *= 0.017453292519943295769236907684886;
switch(choice)
{
case 1:
xp=x;
yp=cos(theta)*y-sin(theta)*z;
zp=sin(theta)*y+cos(theta)*z;
break;
case 2:
xp=cos(theta)*x+sin(theta)*z;
yp=y;
zp=-sin(theta)*x+cos(theta)*z;
break;
case 3:
xp=cos(theta)*x-sin(theta)*y;
yp=sin(theta)*x+cos(theta)*y;
zp=z;
break;
default:
xp=x;
yp=y;
zp=z;
}
x=xp;y=yp;z=zp;
}
double vetor::abs(void)//取向量模
{
return (sqrt(x*x+y*y+z*z));
}
void vetor::display(void)//显示向量
{
cout<<"向量为: ("<
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯