“CPP -Vorlage” Code-Antworten

Vorlage c

#include <iostream>
using namespace std;
 
// One function works for all data types.  This would work
// even for user defined types if operator '>' is overloaded

template <typename T>
T myMax(T x, T y)
{
   return (x > y)? x: y;
}
 
int main()
{
  cout << myMax<int>(3, 7) << endl;  // Call myMax for int
  cout << myMax<double>(3.0, 7.0) << endl; // call myMax for double
  cout << myMax<char>('g', 'e') << endl;   // call myMax for char
 
  return 0;
}
Graceful Gerbil

CPP -Vorlage

#include <iostream>
using namespace std;

int main()
{
  return 0;
}
Innocent Ibex

Vorlage c

template <class myType>
myType GetMax (myType a, myType b) {
 return (a>b?a:b);
}
Panicky Pelican

C Vorlage

template <class T>
class mypair {
    T values [2];
  public:
    mypair (T first, T second)
    {
      values[0]=first; values[1]=second;
    }
};
Modern Millipede

Vorlage c

template <class identifier> function_declaration;
template <typename identifier> function_declaration;

//Example:
template <class Type> 
void Swap( Type &x, Type &y)
{
    Type Temp = x;
    x = y; 
    y = Temp;
}
BreadCode

C Vorlage

template <class  T>//or <typename T> it´s the same
 //T can be int, float, double, etc. 
//simple use example: 
T sum(T a, T b)
{
  return a + b;
}
sum(5.0f, 10f);//sum using float
sum(2,3);//sum using int
Vivacious Vendace

Ähnliche Antworten wie “CPP -Vorlage”

Fragen ähnlich wie “CPP -Vorlage”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen