Ten kod nie skompilować na g ++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3, z tym błędemoczekuje podstawowej przed wyrazem ">" w g ++, ale nie w programie Microsoft kompilator
test.cpp: In function ‘T mul(V&, V&)’:
test.cpp:38:27: error: expected primary-expression before ‘>’ token
test.cpp:38:29: error: expected primary-expression before ‘)’ token
test.cpp:38:53: error: expected primary-expression before ‘>’ token
test.cpp:38:55: error: expected primary-expression before ‘)’ token
ale kompiluje i wykonuje poprawnie Microsoft C/C++ optymalizacja kodu wynikowego Wersja 15.00.21022.08 dla x64
#include <iostream>
#include <complex>
template <class T>
class SM
{
public:
T value;
};
template <class T>
class SC : public SM<T>
{
};
class PSSM {
public:
template <class T>
T & getSC() { return sc; }
private:
SC<double> sc;
};
class USSM {
public:
template <class T>
T & getSC() { return sc; }
private:
SC<std::complex<double> > sc;
};
template <class T, class V>
T mul(V & G, V & S) {
return (G.getSC<SC<T> >().value * S.getSC<SC<T> >().value); // error is here
}
int main() {
PSSM p;
PSSM q;
p.getSC<SC<double> >().value = 5;
q.getSC<SC<double> >().value = 3;
std::cout << mul<double>(p,q);
}
nie rozumiem gdzie jest problem. Czy każdy może zrozumieć, jak go obejść lub wyjaśnić naturę problemu w g ++?
ale czemu nie jest poprawnie przetwarzane na początku? gdzie powstaje niejednoznaczność? –
Bez słowa kluczowego "szablon", niektóre kompilatory mylą listę parametrów typu z operatorem mniejszym niż. – bstamour
Najbrzydszy. Disambiguator. Zawsze. – mfontanini