由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C++里能否在运行时check一个object里的member的名字,并且找出其指针?
相关主题
C++(非VC++) 删除链表时如何对指针操作? 在线等回复!谢谢!An object of A automatically converted to an object of B.
开源图片/文本分析[合集] C++ private member question
问两个C++面世小问题有装g++的指南吗?
c++指针的问题一道面试怪题C++. (转载)
琢磨了一下c++ smart pointer,发现不能到处用class D:public B;
C++的一个大问题是裸指针不是对象的身份证C++ Template Question
小白请教一个C++问题:问什么我不能把两个指针=起来?recursive template?
C++ class cross reference problemC++ memcpy declaration use restrict keyword?
相关话题的讨论汇总
话题: c++话题: 指针话题: member话题: 名字话题: studenta
进入Programming版参与讨论
1 (共1页)
l***1
发帖数: 22
1
比如有一个class
class student
{
int studentID;
float height;
};
studentA student;
然后在运行中,要找出有多少member在studentA里,并且知道它们的名字,类型,得到
它们的指针。
还是老老实实在程序里写出各变量名?
t****t
发帖数: 6806
2
不管是runtime还是compile time,C++是不能枚举member的.

【在 l***1 的大作中提到】
: 比如有一个class
: class student
: {
: int studentID;
: float height;
: };
: studentA student;
: 然后在运行中,要找出有多少member在studentA里,并且知道它们的名字,类型,得到
: 它们的指针。
: 还是老老实实在程序里写出各变量名?

b***i
发帖数: 3043
3
你的目的是什么?

【在 l***1 的大作中提到】
: 比如有一个class
: class student
: {
: int studentID;
: float height;
: };
: studentA student;
: 然后在运行中,要找出有多少member在studentA里,并且知道它们的名字,类型,得到
: 它们的指针。
: 还是老老实实在程序里写出各变量名?

x****u
发帖数: 44466
4
虽然C++本身做不到,不过不少framework可以实现类似功能。

【在 l***1 的大作中提到】
: 比如有一个class
: class student
: {
: int studentID;
: float height;
: };
: studentA student;
: 然后在运行中,要找出有多少member在studentA里,并且知道它们的名字,类型,得到
: 它们的指针。
: 还是老老实实在程序里写出各变量名?

l***1
发帖数: 22
5
能否举几个例子?
多谢。

【在 x****u 的大作中提到】
: 虽然C++本身做不到,不过不少framework可以实现类似功能。
l***1
发帖数: 22
6
比如想自动存一个Class里的所有变量。想编写一个universal的函数。
不过看到 Boost和OpenCV的XML saving都做不到这点。

【在 b***i 的大作中提到】
: 你的目的是什么?
l***1
发帖数: 22
7
Thank you.

【在 t****t 的大作中提到】
: 不管是runtime还是compile time,C++是不能枚举member的.
b***i
发帖数: 3043
8
如果可以,能写出你希望的语法吗?就是这个函数的声明和使用的例子?

【在 l***1 的大作中提到】
: 比如想自动存一个Class里的所有变量。想编写一个universal的函数。
: 不过看到 Boost和OpenCV的XML saving都做不到这点。

x****u
发帖数: 44466
9
比如说COM里面的automation,就部分实现了这个功能。

【在 l***1 的大作中提到】
: 能否举几个例子?
: 多谢。

tc
发帖数: 21
10
为存数据的话可用protocol buffer
http://code.google.com/p/protobuf/

【在 l***1 的大作中提到】
: 比如有一个class
: class student
: {
: int studentID;
: float height;
: };
: studentA student;
: 然后在运行中,要找出有多少member在studentA里,并且知道它们的名字,类型,得到
: 它们的指针。
: 还是老老实实在程序里写出各变量名?

相关主题
C++的一个大问题是裸指针不是对象的身份证An object of A automatically converted to an object of B.
小白请教一个C++问题:问什么我不能把两个指针=起来?[合集] C++ private member question
C++ class cross reference problem有装g++的指南吗?
进入Programming版参与讨论
d***q
发帖数: 1119
11

BSON as well...but less declarative.

【在 tc 的大作中提到】
: 为存数据的话可用protocol buffer
: http://code.google.com/p/protobuf/

i*********n
发帖数: 58
12
What do want to do exactly?
l*******G
发帖数: 1191
13
in matlab this is called fieldnames() function, not sure how they realized
it.
J*****n
发帖数: 4859
14

名字和变量还是很容易拿到的,至于指针就太底层了。

【在 l***1 的大作中提到】
: 比如有一个class
: class student
: {
: int studentID;
: float height;
: };
: studentA student;
: 然后在运行中,要找出有多少member在studentA里,并且知道它们的名字,类型,得到
: 它们的指针。
: 还是老老实实在程序里写出各变量名?

D*******a
发帖数: 3688
15
C++ does not have reflection, but you may be able to use some sophisticated
macro to achieve this.

【在 l***1 的大作中提到】
: 比如有一个class
: class student
: {
: int studentID;
: float height;
: };
: studentA student;
: 然后在运行中,要找出有多少member在studentA里,并且知道它们的名字,类型,得到
: 它们的指针。
: 还是老老实实在程序里写出各变量名?

t****t
发帖数: 6806
16
请教怎么自动拿到"名字和变量"?

【在 J*****n 的大作中提到】
:
: 名字和变量还是很容易拿到的,至于指针就太底层了。

U9
发帖数: 25
17
Visual C++, I think, they maybe can do that.

【在 t****t 的大作中提到】
: 请教怎么自动拿到"名字和变量"?
f*****e
发帖数: 2992
18
记得是不是有个
__function__的宏,集采函数名字。

sophisticated

【在 D*******a 的大作中提到】
: C++ does not have reflection, but you may be able to use some sophisticated
: macro to achieve this.

a9
发帖数: 21638
19
那也是编译过程用的。

站: BBS 未名空间站 (Fri Jun 15 18:27:41 2012, 美东)

【在 f*****e 的大作中提到】
: 记得是不是有个
: __function__的宏,集采函数名字。
:
: sophisticated

l*******G
发帖数: 1191
20
Debug 时显然可以,那么把GCC 修改一下,在每个class和structure里加一个return_
members()函数,貌似可以。
k********u
发帖数: 148
21
C++ Prime 里曾经曰过 (记得是)用public函数return可以访问私有成员。(同意楼
上的)
1 (共1页)
进入Programming版参与讨论
相关主题
C++ memcpy declaration use restrict keyword?琢磨了一下c++ smart pointer,发现不能到处用
int *a [] 和int (*a)[] 一样吗C++的一个大问题是裸指针不是对象的身份证
如何让一个指针指向一个多维数组小白请教一个C++问题:问什么我不能把两个指针=起来?
内存泄露了吗?C++ class cross reference problem
C++(非VC++) 删除链表时如何对指针操作? 在线等回复!谢谢!An object of A automatically converted to an object of B.
开源图片/文本分析[合集] C++ private member question
问两个C++面世小问题有装g++的指南吗?
c++指针的问题一道面试怪题C++. (转载)
相关话题的讨论汇总
话题: c++话题: 指针话题: member话题: 名字话题: studenta