C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Koenig-Lookup und Konstruktoren

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German)
View previous topic :: View next topic  
Author Message
Hubert Schmid
Guest





PostPosted: Mon Nov 24, 2003 7:59 pm    Post subject: Koenig-Lookup und Konstruktoren Reply with quote



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





PostPosted: Tue Nov 25, 2003 10:54 pm    Post subject: Re: Koenig-Lookup und Konstruktoren Reply with quote



"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





PostPosted: Sat Nov 29, 2003 3:56 pm    Post subject: Re: Koenig-Lookup und Konstruktoren Reply with quote



"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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.