C++에서 함수를 정의하고 호출하는 유형은 다음과 같다.
함수의 종류
* 정적함수 - 전역함수① - namespace 내의 전역함수② - static 멤버함수③ * 멤버함수④
함수의 호출 유형 * 정적함수의 호출 * 객체를 통한 멤버함수의 호출 * 객체의 주소를 통한 멤버함수의 호출
#include "stdafx.h"
#include <iostream>
using namespace std;
void Test()
{
cout << "정적함수 :: 전역함수\n";
}
namespace TestNamespace
{
void Test()
{
cout << "정적함수 :: namespace 내의 전역함수\n";
}
}
class TestClass
{
public:
static void Test()
{
cout << "정적함수 :: static 멤버함수\n";
}
void TestMember()
{
cout << "멤버함수\n";
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Test();// ① - 정적함수 호출
TestNamespace::Test();// ② - 정적함수 호출
TestClass testClass;
testClass.Test();// ③ - 객체를 통한 정적함수 호출
testClass.TestMember();// ④ - 객체를 통한 멤버함수 호출
TestClass* testPoint = &testClass;
testPoint->Test();// ③ - 객체의 주소를 통한 정적함수 호출
testPoint->TestMember();// ④ - 객체의 주소를 통한 멤버함수 호출
return 0;
}