00001 00007 #include<iostream> 00008 00009 struct ficheLogin { 00010 std::string Nom; 00011 std::string Prenom; 00012 std::string Telephone; 00013 std::string Login; 00014 }; 00015 00016 template<typename Validator, 00017 bool (*IsValid)(const std::string& t) = &Validator::isValid, 00018 void (*CorrectForm)() = &Validator::correctForm > 00019 struct registerLogin { 00020 ficheLogin newLogin(){ 00021 ficheLogin f; 00022 std::cout << "Nom:" << std::endl; 00023 std::cin >> f.Nom; 00024 std::cout << "Prénom:" << std::endl; 00025 std::cin >> f.Prenom; 00026 std::cout << "Telephone:" << std::endl; 00027 do{ 00028 CorrectForm(); 00029 std::cin >> f.Telephone; 00030 } while(!IsValid(f.Telephone)); 00031 std::cout << "Login:" << std::endl; 00032 std::cin >> f.Login; 00033 return f; 00034 } 00035 }; 00036 00037 struct StandardValidator{ 00038 static bool isValid(const std::string& t){ 00039 if(t.length()!=10) 00040 return false; 00041 for(int i=0;i<10;i++) 00042 if(t[i]<'0' || t[i]>'9') 00043 return false; 00044 return true; 00045 } 00046 static void correctForm(){ 00047 std::cout << "10 chiffres sans espace" << std::endl; 00048 } 00049 private: 00050 StandardValidator() {} 00051 StandardValidator(const StandardValidator&) {} 00052 }; 00053 00054 int main() { 00055 registerLogin<StandardValidator> r; 00056 ficheLogin f=r.newLogin(); 00057 }