#include <iostream>
float add(const float& a, const float& b)
{
return a + b;
}
float multiply(const float& a, const float& b)
{
return a * b;
}
float worker(const float& a, const float& b, float(*func_ptr)(const float& a, const float& b))
{
return (*func_ptr)(a, b);
}
void main(void)
{
float a = 1.1f;
float b = 3.3f;
std::cout << add(a, b) << " " << std::endl;
std::cout << multiply(a, b) << " " << std::endl;
std::cout << std::endl;
float(*func_ptr)(const float& a, const float& b);
func_ptr = &add;
std::cout << func_ptr(a, b) << " " << std::endl;
func_ptr = &multiply;
std::cout << func_ptr(a, b) << " " << std::endl;
std::cout << std::endl;
std::cout << worker(a, b, &add) << " " << std::endl;
std::cout << worker(a, b, &multiply) << " " << std::endl;
std::cout << std::endl;
system("pause");
}
'Programming > C,C++' 카테고리의 다른 글
Piano 예제 (0) | 2017.02.26 |
---|---|
Vector2D 예제 (0) | 2017.02.25 |
STL list 예제 코드[펌] (0) | 2017.02.14 |
Template 예제 (0) | 2017.01.24 |
class와 OOP 예제3 virtual function (0) | 2017.01.20 |