C++????????????
???????????? ???????[ 2015/2/3 13:55:51 ] ????????C++ ????
????C++?????????ν????????????????????????????????????????????????????????????????????嵽???????????????????????????????????
?????????????????????????????????????????β??????????????????????????
???????????????????http://blog.csdn.net/vagrxie/article/details/1586340
1 #include <string>
2 #include <iostream>
3 using namespace std;
4
5 class Fruit //??????????????Fruit
6 {
7 string name; //???????name???
8 string colour; //???????colour???
9
10 public:
11 bool isSame(const Fruit &otherFruit) //??????β????????Fruit???????????????
12 {
13 return name == otherFruit.name;
14 }
15 void print() //?????????????????print()
16 {
17 cout<<colour<<" "<<name<<endl;
18 }
19 Fruit(const string &nst??const string &cst = "green"):name(nst)??colour(cst){} //??????
20
21 Fruit(){}
22 };
23
24 int main(void)
25 {
26 Fruit apple("apple");
27 Fruit orange("orange");
28 cout<<"apple = orange ?: "<<apple.isSame(orange)<<endl; //?????????????
29 cout<<"apple = apple ?:"<<apple.isSame(string("apple"))<<endl; //?????string???βΣ?
30
31 return 0;
32 }
??????????string("apple")?????????????Fruit?????βε???????????????????????????????colour????????????????????????????????????????????????????????Fruit apple("apple")?????????????????????const char *??C????????????string????apple.isSame("apple")??????????????????????string???????????????????????????????string???????Fruit???????????????????????apple.isSame(Fruit("apple"))??
????????????????????????explicit??????????????????????????????ù???????explicit???????????????????????????????????????????????????岻?????????????????????????????????????????????磺apple.isSame(Fruit("apple"))??
?????????
??????1???????ù????????????????????ù????????κι??????????????????????????????
??????2????????????????????????????????????????????βι?????????explicit???????????????explicit???????????????????????????????????????????
??????3???????????????explicit????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??????
???·???
??????????????????
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