1.函数后面加constant是什么意思呀
首先,是加const不是constant。
函数后面加const是表明这个函数不会更改class的状态,即class内各成员变量的值。编译器如果发现某个const函数里改变了成员变量的值会报错。比如下面这个例子。
struct A {
int i;
void set(int v) {i = v;} //不能加const,因为i值改变了。
int value() const {return i;} //正确,i值没有改变。
int value2() const {return i++;} //错误,因为i值改变了。必须将const去掉。
};
如果函数比较复杂时,比如并不直接改变某个值,但是调用了其它函数,编译器怎么判断函数是否const呢。可以看下面的例子。
struct B {
A a; //B里包含一个A类成员。
int func1() const {return a.value();} //正确,所调用的a.value()也是一个const函数。
int func2() const {return a.value2();} //错误,a.value2()不是const函数。
};
也就是说,在const函数里只能调用成员的const函数以保证成员状态不会改变。
所以,在设计类的函数里,区别const和非const函数并标记出来是个好习惯,既保证自己不会对类误操作,也可以明示别人调用你的类里哪些会改变类状态。
2.接上面的问constant.h
cout<<struct_fun.int_constant<<"\t(fun.int_constant in constant)\t"<<lenth_1<<"\tlenth_1 in constant"<<endl;
cout<<c<<"\t(c in constant1)"<<endl;
c = file_f.get();
cout<<c<<" \tc in constant2"<<endl;
if(c == '.')
{
file_f.get(c);
if(!is_digit(c))
cout<<"Error in constant \""<<struct_fun.int_constant<<"\""<<endl;
int_const(int_temp, lenth_2, c, file_f);
//struct_fun.class_type[] = {'r','e','a','l','_','c','\0'};
//上面这句就更郁闷了 字符数组赋值这样为什么不对
//有办法直接赋值串么 比如 struct_fun.class_type[] = "XXXX"
//这个不是主要问题 不过能给讲解一下字符串的赋值。。怎么操作最好了
//格外感谢
struct_fun.real_constant = struct_fun.int_constant + int_temp * pow(0.1, lenth_2);
}
else
{
//struct_fun.class_type[] = {'i','n','t','_','c','\0'};
//这句也是
}
}
#endif
提问者: 卍gutoo卍 - 四级
3.diversity statement怎么写
diversity statement
多样性陈述
例句:
The most striking characteristic of the electric power production statistics and information system is the constant change of the contents concerning the statistics such as that of the demand and the diversity in the form of representation or the statement of the statistical results.
电力生产信息统计最显著的特点是统计内容、运算关系的需求在不断变化及统计结果的表示形式即报表具有多样性。
重点词汇:
diversity
n. 差异;多样化,
例句:
1
His object is to gather as great a diversity of material as possible.
他的目标就是尽可能多地搜集各种材料。
2
We have nothing against diversity; indeed, we want more of it
我们一点都不抵触多样化;实际上,我们需要多样性更丰富一些。
转载请注明出处育才学习网 » constant类怎么写