jeudi 29 septembre 2016

Possible c++11 instance template error on Visual studio 2015

run following code, seems the compiler defined an empty printf();

template<typename T>
void printf(T value) {
    std::cout << value << std::endl;
    cout << "case 1" << endl;
}

template<typename T, typename... Args>
void printf(T value, Args... args) {
    printf(value);
    cout << "...";
    printf(args...);
    cout << "case 2" << endl;
}
int main() {
    printf(1, 2, "123", 1.1);
    return 0;
}

I'm using vs 2015 with newest patch. The output is:

1
case 1
...2
case 1
...123...1.1
case 1
case 2
case 2
case 2

Aucun commentaire:

Enregistrer un commentaire