 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Vincent Richard Guest
|
Posted: Tue Jul 15, 2003 3:03 pm Post subject: Erreur bizarre |
|
|
Bonjour,
Quelqu'un peut-il m'expliquer pourquoi j'obtiens une erreur de compilation
avec le programme suivant (voir plus bas) ?
[vincent@Sherlock tmp]$ g++ -ansi -Wall -pedantic -o prob prob.cpp
prob.cpp: Dans constructor « A::A() »:
prob.cpp:57: erreur d'analyse syntaxique avantle jeton « ; »
prob.cpp:58: rendu confus par les erreurs précédentes, abandon
[vincent@Sherlock tmp]$ g++ --version
g++ (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
Voici le code :
#include <string>
class S
{
public:
static S* getInstance() { return (inst ? inst : (inst = new S)); }
const std::string& get() const { return str; }
private:
S() { }
~S() { }
static S* inst;
std::string str;
};
S* S::inst = NULL;
class T
{
public:
T(const std::string& s) { str = s; }
inline operator const std::string&() { return (str); }
private:
std::string str;
};
class M
{
public:
M(const std::string &s) { /* ... */ }
};
class A
{
public:
A()
{
// OK
const std::string& s = S::getInstance()->get();
M m1(T(s));
// KO
M m2(T(S::getInstance()->get())); // ligne 57
}
};
int main()
{
A a;
}
Merci d'avance pour vos réponses.
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 |
|
 |
Jean-Marc Bourguet Guest
|
|
| Back to top |
|
 |
Gabriel Dos Reis Guest
|
Posted: Tue Jul 15, 2003 3:38 pm Post subject: Re: Erreur bizarre |
|
|
Vincent Richard <chere-loque.MARRE-DE-LA-PUB (AT) wanadoo (DOT) fr.invalid> writes:
| Quote: | prob.cpp:57: erreur d'analyse syntaxique avantle jeton « ; »
|
Tien, je ne savais pas que dans ce contexte, ils traduiraient toekn
par jeton.
[...]
| Quote: | // OK
const std::string& s = S::getInstance()->get();
M m1(T(s));
|
Ceci est une déclaration de fonction nommée m1 prenant un T et
retournant un M -- le paramètre formel se nomme s, qui n'a rien à
avoir avec la ligne au dessus.
| Quote: | // KO
M m2(T(S::getInstance()->get())); // ligne 57
|
Toutes les version courantes de GCC en production (i.e. précédant
GCC-3.4) ont des problèmes pour parser une construction.
-- Gaby
|
|
| 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
|
|