c++/over.cpp
author Markus Bröker<broeker.markus@googlemail.com>
Sat, 21 Oct 2017 13:45:05 +0200
changeset 171 c6e0af68825a
parent 165 f551b78c3eee
permissions -rw-r--r--
Entrypoint and RET fixed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
165
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
#include <iostream>
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     2
#include <cstdlib>
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     3
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
template<class T>
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
T add(T a, T b)
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
{
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
	return a+b;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
}
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    10
int add (int a, int b)
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
{
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
	std::cout << "overloaded..." << std::endl;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
	return b+a;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
}
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
int main(int argc, char **argv)
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
{
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
	float a, b;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    19
	int c, d;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
    std::string s1, s2;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
    a = 1.0;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    23
    b = 2.5;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
    c = 1;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
	d = 2;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    27
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
	s1 = "Hello ";
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    29
	s2 = "World!";
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    30
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
	std::cout << add (a, b) << std::endl;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    32
	std::cout << add (c, d) << std::endl;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    33
	std::cout << add (s1, s2) << std::endl;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    34
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    35
	return EXIT_SUCCESS;
f551b78c3eee a bluetooth and a c++ demo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    36
}