Uso de tipos de plantillas de C++

#include <iostream>
#include "library.h"
 
void hello() {
    std::cout << "Hello, World!" << std::endl;
}


#ifndef MYSHAREDLIB_LIBRARY_H
#define MYSHAREDLIB_LIBRARY_H
 
// 打印 Hello World!
void hello();
 
// 使用可变模版参数求和
template <typename T>
T sum(T t)
{
    return t;
}
template <typename T, typename ...Types>
T sum(T first, Types ... args)
{
    return first + sum<T>(args...);
}
 
#endif

Porque la elipsis tiene infinitas posibilidades.

Expandir hacia el infinito es copiar infinitamente.La parte con puntos suspensivos, el operador anterior también es superposición repetida.

Supongo que te gusta

Origin blog.csdn.net/u013590327/article/details/123044046
Recomendado
Clasificación