 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
yeye yaya Guest
|
Posted: Fri Jul 11, 2003 6:57 pm Post subject: pkoi ca marche pas |
|
|
Hello,
Why doesn't this work? it says
" error C2450: switch expression of type 'class CString' is illegal
No user-defined-conversion operator available that can perform this
conversion, or the operator cannot be called "
And is there a solution?
//Code starts here
void CDay2Dlg::OnRunpgm()
{
UpdateData(true);
CString strPgmName;
strPgmName = m_strProgToRun;
strPgmName.MakeUpper();
switch(strPgmName) {
case "PAINT":
WinExec("pbrush.exe",SW_SHOW);
break;
case "NOTEPAD":
WinExec("notepad.exe",SW_SHOW);
break;
case "SOLITAIRE":
WinExec ("sol.exe",SW_SHOW);
break;
}
}
|
|
| Back to top |
|
 |
Alain Naigeon Guest
|
Posted: Fri Jul 11, 2003 7:08 pm Post subject: Re: pkoi ca marche pas |
|
|
"yeye yaya" <rthriller (AT) excite (DOT) com> a écrit dans le message news:
ben199$uie$1 (AT) news-reader8 (DOT) wanadoo.fr...
| Quote: | Hello,
Why doesn't this work? it says
" error C2450: switch expression of type 'class CString' is illegal
No user-defined-conversion operator available that can perform this
conversion, or the operator cannot be called "
And is there a solution?
//Code starts here
void CDay2Dlg::OnRunpgm()
{
UpdateData(true);
CString strPgmName;
strPgmName = m_strProgToRun;
strPgmName.MakeUpper();
switch(strPgmName) {
case "PAINT":
|
....
1) "pkoi" s'écrit "pourquoi" - sinon le compilateur de Français râle.
2) l'expression testée par switch doit être un type entier ou
énuméré ; ce peut être une classe, mais évidemment à
la condition qu'elle ait un opérateur de conversion vers
l'un des deux types précédents.
3) il faut croire que la classe CString (propriétaire MS je crois),
n'a pas un tel opérateur - d'ailleurs on voit mal ce qu'il
pourrait être.
4) il faut donc remplacer ton switch par une collection de
tests ordinaires par if...
--
Français *==> "Musique renaissance" <==* English
midi - facsimiles - ligatures - mensuration
http://anaigeon.free.fr | http://www.medieval.org/emfaq/anaigeon/
Alain Naigeon - [email]anaigeon (AT) free (DOT) fr[/email] - Strasbourg, France
|
|
| Back to top |
|
 |
Luc Hermitte Guest
|
Posted: Fri Jul 11, 2003 7:29 pm Post subject: Re: pkoi ca marche pas |
|
|
Salut.
Tout d'abord, permets moi de te rapeller que "fr" dans
"fr.comp.lang.c++" implique "en langue *FR*ançaise" -- pourtant, ton
sujet est bien en langue française d'ailleurs.
"yeye yaya" <rthriller (AT) excite (DOT) com> wrote in news:ben199$uie$1@news-
reader8.wanadoo.fr:
| Quote: | void CDay2Dlg::OnRunpgm()
{
[...]
CString strPgmName = m_strProgToRun;
[...]
switch(strPgmName) {
[...]
}
}
Why doesn't this work? it says
" error C2450: switch expression of type 'class CString' is illegal
No user-defined-conversion operator available that can perform this
conversion, or the operator cannot be called "
|
C'est pourtant clair. Un switch ne peut se faire sur un type de classe
CString.
En fait, un switch ne peut se faire _que_ sur des types énumérables
(entiers et dérivés).
Tu vas donc devoir employer au choix :
- des
if(...) {...}
elseif (...) {...}
elseif (...) {...}
...
else {...}
Traduction classique du switch ...
- des std::maps
typedef std::map<std:string, std::string> table;
table table_assoc;
table_assoc["Paint"] = "pbrush.exe";
...
...
table::const_iterator ch =
find(table_assoc.begin(), table_assoc.end(), laChaineCherchee);
if (table_assoc.end() != ch)
WinExec(ch.first.c_str(), ch.second.str(), SW_SHOW);
else
std::err << "le programme " << laChaineCherchee
<< "n'est pas référencé" << std::endl;
Avantage : peut-etre étendu sans recompilation
Il y a encore d'autres façon de faire la même chose. Façon plus ou moins
souples/complexes/évolutives/...
--
Luc Hermitte
FAQ de <news:fr.comp.lang.c++> :
<http://www.cmla.ens-cachan.fr/~dosreis/C++/FAQ/>
Dejanews : <http://groups.google.com/advanced_group_search>
|
|
| Back to top |
|
 |
yeye yaya Guest
|
Posted: Fri Jul 11, 2003 8:17 pm Post subject: Re: pkoi ca marche pas |
|
|
Je suis désolé pour mon français et pour la partie en anglais du message.
Je viens de Delphi pour découvrir et migrer vers c++ et je rencontre de
serieux problèmes pour travailler avec du texte (chose evidente sous
delphi), toute aide sera la bienvenue.
Merci
|
|
| Back to top |
|
 |
Vincent Richard Guest
|
Posted: Fri Jul 11, 2003 8:57 pm Post subject: Re: pkoi ca marche pas |
|
|
Le Vendredi 11 Juillet 2003 22:17, yeye yaya a écrit :
| Quote: | Je viens de Delphi pour découvrir et migrer vers c++ et je rencontre de
serieux problèmes pour travailler avec du texte (chose evidente sous
delphi), toute aide sera la bienvenue.
|
Un bon conseil : utiliser tous les outils fournis par la bibliothèque
standard (STL) : "std::vector" pour les tableaux, "std::string" pour
manipuler les chaînes de caractères, etc...
Vincent
--
SL> Au fait elle est mieux ma signature maintenant ?
Oui. T'enlève encore les conneries que t'as écrit dedans et c'est bon.
-+- JB in <http://www.le-gnu.net> : Le neuneuttoyage par le vide -+-
|
|
| Back to top |
|
 |
Emmanuel Delahaye Guest
|
Posted: Sat Jul 12, 2003 9:33 am Post subject: Re: pkoi ca marche pas |
|
|
In 'fr.comp.lang.c++', Luc Hermitte <hermitte (AT) free (DOT) fr.invalid> wrote:
| Quote: | Tu vas donc devoir employer au choix :
- des
if(...) {...}
elseif (...) {...}
|
else if (...) {...}
--
-ed- [email]emdelYOURBRA (AT) noos (DOT) fr[/email] [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|