ssercpp12 / Homework

Homework result for 12 sser cpp
1 stars 8 forks source link

HW4---bool get函数的疑问 #11

Open YouseYeung opened 11 years ago

YouseYeung commented 11 years ago

// These methods allow the convenient retrieval of settings. // If the current setting object can be converted into the given type, // the value is returned through the |out_value| parameter and true is // returned; otherwise, false is returned and |out_value| is unchanged. virtual bool GetAsBoolean(bool* out_value) const; virtual bool GetAsInteger(int* out_value) const; virtual bool GetAsDouble(double* out_value) const; virtual bool GetAsString(std::string* out_value) const; 求师兄用中文解释一下,小弟英文水平太渣了 T T

ssercpp12 commented 11 years ago

Use case for your reference.

FundamentalValue fv(100);
int out_value = 0;
fv.GetAsInteger(&out_value);   // should return true, and out_value will be 100.

bool flag = false;
fv.GetAsBoolean(&flag);   // should return false, and flag doesn't change.
YouseYeung commented 11 years ago

3Q!!!

YouseYeung commented 11 years ago

FundamentalValue fv(100); double out_value = 0; fv.GetAsInteger(&out_value);

// Should it retrun true or false?

ssercpp12 commented 11 years ago

Your code can compile? The argument of GetAsInteger only receive int*, and you pass a double*.

HuangLK commented 11 years ago

FundamentalValue fv(100); double out_value = 0; fv.GetAsDouble(&out_value);

It retrun false,doesn't it?

zhchbin commented 11 years ago

Yes @acefromsysu .

HuangLK commented 11 years ago

Thanks for your reply. ^ ^

Yueyi commented 11 years ago

How to judge the data type of fv ?

zhchbin commented 11 years ago

@Yueyi Please read the homework_4.pdf. The answer is easy enough to get.

Yueyi commented 11 years ago

OK,I got it.