|
1.How to get the size of an array?
- template<typename T,unsigned int size>
- unsigned int test(T(&arr)[size])
- {
- return size;
- }
复制代码
2.How to implement a final class?
- class CFinal
- {
- CFinal(){}
- public:
- static CFinal* new_object()
- {
- return new CFinal;
- }
- static CFinal get_instance()
- {
- return CFinal();
- }
- };
复制代码
3.How to fix the wrong input when we need an integer?
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- int apple;
- cout<<"Please input an integer:"<<endl;
- cin>>apple;
- while(!cin)
- {
- cout<<"Wrong! Input again!"<<endl;
- cin.clear();
- string tmp;
- cin>>tmp>>apple;
- }
- cout<<apple<<endl;
- return 0;
- }
复制代码 |
|