C++????????????
???????????? ???????[ 2015/6/12 11:04:53 ] ???????????????? C++
????C++???????????????????????“????”?????????C++???????????????????????????и?????????С?????????????СС??????
???????????????????????????????????
??????????????Effective C++?? lostmouse???????
class TestInt
{
public:
int GetData()const{ return i;};
TestInt(int ii):i(ii){}; //????????
private:
int i;
};
void fun(TestInt t)
{
cout<<t.GetData()<<endl;
}
int main()
{
fun(10);
return 0;
}
???????н????
????10
??????fun???????????TestInt???????????????????int ????????
????????????????????????????????????±???????????????error: conversion from ‘int’ to non-scalar type ‘TestInt
?????????е?ü????????????ó????????????????????й?????????C++?е?????????????
?????????????????fun?????int?????????????TestInt????????????????TestInt?????????int?????????????TestInt??
????????????????????????????????????????????????? const TestInt t??10?????????????????????
??????Effective C++????????????
????class Month {
????public:
????static const Month Jan() { return 1; }
????static const Month Feb() { return 2; }
????...
????static const Month Dec() { return 12; }
????int asInt() const // ???????Month
????{ return monthNumber; } // ?????????int
????private:
????Month(int number): monthNumber(number) {}
????const int monthNumber;
????};
????????????????ε????????????? static const Month Jan() { return 1; }
??????????????????к????????????????????Month????????????????int???
?????????????y?????????????????δε?????????ū?????????÷???
?????????????????????const???·??Month jan = Month::Jan(); ?????????????·?????
?????? static const Month Jan() { return 1; } ?????????????????????????????????????????
??????е?????????????????μ?month??
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11