
不好意思,可能问的比较菜。我在试验用C实现多态的时候,遇到了这个问题:
[code]//poly.c
#include
struct STU { char num[10]; float score[3]; }; main() { struct stu s[3]={{“20021”,90,95,85}, {“20022”,95,80,75}, {“20023”,100,95,90}},*p=s; int i; float sum=0; for(i=0;i<3,i++) sum=sum+p->;score; printf(“%6.2f\n”,sum); } 程序运行后的输出结果是 A) 260.00 B) 270.00 C) 280.00 D) 285.00
[quote] /** * idr_remove - remove the given id and free it's slot * idp: idr handle * id: uniqueue key */ void idr_remove(struct idr *idp, int id) { struct idr_layer *p; /* Mask off upper bits we don't use for the search. */ id &= MAX_ID_MASK; sub_remove(idp, (idp->layers - 1) * IDR_BITS, id); if (idp->top && idp->top->count == 1 && (idp->layers > 1) && idp->top->ary[0]) { // We c...
[code]class AA { public: ... struct BB{ int a = 0; float b; } privated; BB bb; } [/code] 着重部分那一句,不能这样做,编译器报错(GCC3。2。2) 那我怎样对它做初始化呢?
我在gcc后面加上了-fpack-struct选项后我文件中的结构就可以按照字节对齐了。但是我在调试过程中遇到了其他的问题。不知道还有没有别的方法可以让arm-linux下的结构按字节对齐。
我们知道数组就很简单,用for 循环。
num=length(num_array);
for(i=0;i
struct ST_MY { int id; string val; }; struct ST_MY my; my.id = 1; my.val = "123"; vector<struct ST_MY> vst; vst.push_back(my); 能直接这么做吗?
高手们再试试这个问题: http://bbs.chinaunix.net/thread-1134802-1-1.html [ 本帖最后由 makeclear 于 2008-6-3 12:21 编辑 ]