728x90
반응형
#include <iostream>

template <typename T>
T add(const T a, const T b)
{
	return a + b;
}

template <typename T>
T sub(const T a, const T b)
{
	return a - b;
}

int main(void)
{
	int x = 10;
	int y = 5;

	std::cout << add(x, y) << std::endl;

	std::cout << add(x, sub(x, y)) << std::endl;

	return 0;
}
// Function Pointer
#include <iostream>
using namespace std;

void sayHello(void)
{
	cout << "Hello" << endl;
}

template <typename T>
T sum(T a, T b)
{
	return a + b;
}

int main(void)
{
	void(*hello)(void) = sayHello;
	hello();

	int(*add)(int, int) = sum;
	double(*addD)(double, double) = sum;
	cout << add(2, 3) << endl;
	cout << addD(4.2, 1.2) << endl;

	return 0;
}
728x90
반응형

'Language > C & C++' 카테고리의 다른 글

[C] Function to remove spaces from a string  (0) 2022.10.22
[C]File Input & Ouptut  (0) 2022.10.22
[Instant]Homework  (0) 2022.10.18
[C++]Related to Copy Constructor  (0) 2022.10.17
[C++] this pointer  (0) 2022.10.17

+ Recent posts