[C++] Fehler: mehrdeutiger Aufruf const/nonconst aus Lambda
Verfasst: 31.07.2018, 11:00
Hallo Leute,
ich habe gerade ein seltsames Problem, in dem ich eine template-Methode aus einem Lambda heraus aufrufen will und dazu this capture. Und nur VisualStudio 2017 liefert mir "mehrdeutiger Aufruf", GCC und CLANG kompilieren das sauber. Scheint also ein Compilerbug zu sein, aber wessen Fehler?
Hier live zum Ausprobieren: https://godbolt.org/g/BXQqA1 Compiliert sauber auf GCC und CLANG, liefert auf Visual Studio aber folgende Fehlermeldung
Hat jemand eine Idee, was hier passiert? Bzw. welcher der Compiler recht hat? Der Workaround ist ganz einfach, this in ne Variable zu capturen.
ich habe gerade ein seltsames Problem, in dem ich eine template-Methode aus einem Lambda heraus aufrufen will und dazu this capture. Und nur VisualStudio 2017 liefert mir "mehrdeutiger Aufruf", GCC und CLANG kompilieren das sauber. Scheint also ein Compilerbug zu sein, aber wessen Fehler?
Code: Alles auswählen
#include <tuple>
class A {
public:
std::tuple<int, float, double> t;
template <typename T> T& Get() { return std::get<T>( t); }
template <typename T> const T& Get() const { return std::get<T>( t); }
void foo() {
[this]() { Get<int>(); }();
}
};
Code: Alles auswählen
<source>(11): error C2668: 'A::Get': ambiguous call to overloaded function
<source>(8): note: could be 'const T &A::Get<int>(void) const'
with [ T=int ]
<source>(7): note: or 'T &A::Get<int>(void)'
with [ T=int ]
<source>(11): note: while trying to match the argument list '()'