 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Hubert Schmid Guest
|
Posted: Mon Nov 24, 2003 7:59 pm Post subject: Koenig-Lookup und Konstruktoren |
|
|
Hi,
folgendes Problem mit Koenig-Lookup:
namespace ns {
struct Bar { };
struct Foo { Foo(Bar); };
Foo foo(Bar bar);
}
int main() {
ns::Bar bar;
ns::Foo a = foo(bar);
ns::Foo b = Foo(bar); // error
}
Während die zweitletzte Zeile wie erwartet funktioniert, bekomme ich
in der letzten Zeile die Fehlermeldung (gcc 3.3):
error: no match for call to `(ns::Foo) (ns::Bar&)'
Die Meldung verstehe ich nicht. Funktioniert das Koenig-Lookup nur mit
Funktionen und nicht mit Konstruktoren?
Gruß, Hubert
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Markus Schaaf Guest
|
Posted: Tue Nov 25, 2003 10:54 pm Post subject: Re: Koenig-Lookup und Konstruktoren |
|
|
"Hubert Schmid" <h.schmid-usenet (AT) gmx (DOT) de> schrieb:
| Quote: | namespace ns {
struct Bar { };
struct Foo { Foo(Bar); };
Foo foo(Bar bar);
}
int main() {
ns::Bar bar;
ns::Foo a = foo(bar);
ns::Foo b = Foo(bar); // error
|
Das letzte wäre ein Cast-Ausdruck, falls »Foo« einen Typ bezeichnen würde.
Es wäre ein impliziter Cast, falls Du das »Foo« weggelassen hättest, und
würde problemlos übersetzen.
| Quote: | error: no match for call to `(ns::Foo) (ns::Bar&)'
Die Meldung verstehe ich nicht.
|
Sie ist auch irgendwie blöd.
| Quote: | Funktioniert das Koenig-Lookup nur mit
Funktionen und nicht mit Konstruktoren?
|
C'tors haben keinen Namen, können also auch nicht explizit aufgerufen
werden, können also auch nicht per Lookup gefunden werden.
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Hubert Schmid Guest
|
Posted: Sat Nov 29, 2003 3:56 pm Post subject: Re: Koenig-Lookup und Konstruktoren |
|
|
"Markus Schaaf" <markus (AT) sags-per-mail (DOT) de> writes:
[gekürzt]
| Quote: | "Hubert Schmid" <h.schmid-usenet (AT) gmx (DOT) de> schrieb:
namespace ns {
struct Bar { };
struct Foo { Foo(Bar); };
}
int main() {
ns::Bar bar;
ns::Foo b = Foo(bar); // error
Das letzte wäre ein Cast-Ausdruck, falls »Foo« einen Typ bezeichnen
würde.
error: no match for call to `(ns::Foo) (ns::Bar&)'
|
Den Typ hat er ja "richtig" zu ns::Foo aufgelöst (laut
Fehlermeldung). Und ein Cast von ns::Bar nach ns::Foo existiert mit
dem Konstruktor ja auch. Wieso wendet er den Cast dann nicht an?
Hätte er den Typ ns::Foo bereits gar nicht finden dürfen?
Gruß, Hubert
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| 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
|
|