728x90
    
    
  반응형
    
    
    
  - .h(헤더) 파일에는 함수나 클래스의 선언
- .cpp 파일에는 함수나 클래스의 구현(구현하는 부분에서는 선언한 .h파일을 #include "~~.h"식으로 전처리 해주어야 한다)
 - 이후 함수를 참조하려면 .h파일 전처리(#include) 하면 해당 함수 사용 가능  
test.h
class TestClass{
private:
  int m_testValue;
public:
  void Output();
  void Set(int _value);
  int Get();
}test.cpp
#include <iostream>
#include "test.h"
void Test::Output(){
  std::cout << m_testValue << std::endl;
}
int Test::Get(){
  return m_testValue;
}
void Test::Set(int _value){
  m_testValue = value;
}main.cpp
#include "test.h"
int main(){
 int value = 77;
 Test::Set(value);
 Test::Output(); // 77
 value = -70;
 Test::Set(Test::Get() + value)
 Test::Output(); // 7
 return 0;
}728x90
    
    
  반응형
    
    
    
  'C++' 카테고리의 다른 글
| [C++] 컨텍스트 스위치란 (0) | 2024.03.17 | 
|---|---|
| [C++] 멀티 스레드, 멀티 프로세스 (1) | 2024.03.17 | 
| [C++] 조건문, 스위치문을 줄이기 의한 방법 (0) | 2024.03.16 | 
| [C++] Merger Sort 병합 정렬 (0) | 2024.03.15 | 
| [C++] Quick Sort 퀵 정렬 (1) | 2024.03.15 |