Groups | Search | Server Info | Login | Register
Groups > de.comp.lang.iso-c++ > #2057
| From | Stefan Reuther <stefan.news@arcor.de> |
|---|---|
| Newsgroups | de.comp.lang.iso-c++ |
| Subject | Overloading-Problem |
| Date | 2017-07-19 18:51 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <oko9n8.3qc.1@stefan.msgid.phost.de> (permalink) |
Hallo,
ich bin heute auf ein mir unerklärliches Overloading-Problem gestoßen.
Minimiert sieht das so aus:
----8<--------8<--------8<--------8<--------8<----
#include <string>
template<typename T>
class foo {
public:
foo()
{ }
foo(const foo& f) //1
{ m = f.m; }
template<typename U>
foo(U&& u) //2
{ m = u; }
private:
T m;
};
void bar() {
foo<std::string> a;
foo<std::string> b(a); //3
}
----8<--------8<--------8<--------8<--------8<----
In Zeile //3 wählt der Compiler (z.B. g++-5.4.0 -std=c++11) den Overload
//2 und beschwert sich dann, dass er das keinen passenden
Zuweisungsoperator für 'm = u' findet.
> t.cpp: In instantiation of ‘foo<T>::foo(U&&) [with U = foo<std::__cxx11::basic_string<char> >&; T = std::__cxx11::basic_string<char>]’:
> t.cpp:22:24: required from here
> t.cpp:14:11: error: no match for ‘operator=’ (operand types are ‘std::__cxx11::basic_string<char>’ and ‘foo<std::__cxx11::basic_string<char> >’)
Erwartet hätte ich, dass Overload //1 gewählt wird. Wenn ich //2
auskommentiere, ist das auch der Fall.
Gewohnt bin ich aus C++98, dass der Compiler gerade fürs Kopieren eines
Objektes einen Template-Konstruktor nicht einmal zur Kenntnis nimmt.
Wie bekomme ich das aufgelöst?
Stefan
Back to de.comp.lang.iso-c++ | Previous | Next — Next in thread | Find similar
Overloading-Problem Stefan Reuther <stefan.news@arcor.de> - 2017-07-19 18:51 +0200
Re: Overloading-Problem Florian Weimer <fw@deneb.enyo.de> - 2017-07-19 21:37 +0200
Re: Overloading-Problem Stefan Reuther <stefan.news@arcor.de> - 2017-07-21 20:09 +0200
Re: Overloading-Problem SG <s.gesemann@gmail.com> - 2017-08-13 05:40 -0700
Re: Overloading-Problem SG <s.gesemann@gmail.com> - 2017-08-13 03:12 -0700
csiph-web