Untitled
unknown
c_cpp
a year ago
691 B
5
Indexable
#include <iostream>
template <typename T>
T somma(T a, T b) {
return a + b;
}
int main() {
std::cout << "Somma interi: " << somma(3, 5) << std::endl;
std::cout << "Somma double: " << somma(2.5, 4.3) << std::endl;
return 0;
}
// Online C++ compiler to run C++ program online
#include <iostream>
template <typename T>
class Box{
T valore;
public:
Box(T v) : valore(v) {}
T getValore()
{
return valore;
}
};
int main() {
Box<int> boxInt(42);
Box<std::string> boxStr("Ciao");
std::cout << "Box intero: " << boxInt.getValore() << std::endl;
std::cout << "Box stringa: " << boxStr.getValore() << std::endl;
return 0;
}Editor is loading...
Leave a Comment