C++ 의존 관계 (Dependency)

2021. 3. 19. 19:40·C++/Class

의존 관계 (Dependency)

  • Worker 클래스에서 잠깐 사용하는 Timer 클래스

    main.cpp

    #include "Timer.h"
    #include "Worker.h"
    
    int        main()
    {
      Worker().doSomething();
    }
    
    /* stdout
    4e-07
    */

    Timer.h

    #pragma once
    #include <iostream>
    #include <chrono>
    
    using namespace std;
    
    class Timer
    {
        using clock_t = std::chrono::high_resolution_clock;
        using second_t = std::chrono::duration<double, std::ratio<1>>;
    
        std::chrono::time_point<clock_t> start_time = clock_t::now();
    
    public:
        void elapsed()
        {
            std::chrono::time_point<clock_t> end_time = clock_t::now();
    
            cout << std::chrono::duration_cast<second_t>(end_time - start_time).count() << endl;
        }
    };

    Worker.h

    #pragma once
    
    class Worker
    {
    public:
      void    doSomething();
    };

    Worker.cpp

    #include "Worker.h"
    #include "Timer.h"
    
    void    Worker::doSomething()
    {
      Timer timer;
    
      // do some work here
    
      timer.elapsed();
    }
저작자표시

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

C++ 상속 기본 예제  (0) 2021.03.19
C++ 상속 (Inheritance)  (0) 2021.03.19
C++ 연계, 제휴 관계 (Association)  (0) 2021.03.19
C++ 구성 관계 (Composition Relationship)  (0) 2021.03.19
C++ 객체들의 관계 (Object Relationship)  (0) 2021.03.19
'C++/Class' 카테고리의 다른 글
  • C++ 상속 기본 예제
  • C++ 상속 (Inheritance)
  • C++ 연계, 제휴 관계 (Association)
  • C++ 구성 관계 (Composition Relationship)
Caniro
Caniro
  • Caniro
    Minimalism
    Caniro
  • 전체
    오늘
    어제
    • 분류 전체보기 (316)
      • Algorithm (13)
        • 알기 쉬운 알고리즘 (10)
        • Search (1)
        • Sort (2)
      • Arduino (0)
      • C++ (185)
        • Class (46)
        • Exception (6)
        • Library (51)
        • Overloading (10)
        • SmartPointer (5)
        • Syntax (33)
        • TBC++ (23)
        • Templates (9)
        • VisualStudio (2)
      • Embedded (1)
      • Git (4)
      • Java (5)
      • Linux (16)
        • Error (1)
        • Linux Structure (11)
      • MacOS (7)
      • OS (1)
        • Concurrency (1)
      • Python (21)
        • Class (1)
        • Function (2)
        • Syntax (17)
      • Raspberrypi (9)
      • Review (1)
      • Utility (12)
        • VSCode (5)
        • VirtualBox (3)
      • Web (8)
        • Nginx (1)
        • React (3)
        • Django (1)
      • Windows (19)
        • Registry (3)
        • WSL (1)
        • DeviceDriver (6)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    citrix workspace
    Workspace
    백기선
    알림
    SFC
    로지텍 마우스 제스처
    windows
    스프링 프레임워크 핵심 기술
    시스템 복구
    그림판
    unix
    윈도우
    logi options
    맥북 카카오톡 알림 안뜸
    dism
    윈도우 명령어
    java
    Windows 11
    spring
    MacOS
    EXCLUDE
    SunOS 5.1
    Solaris 10
    vscode
    mspaint
    제외
    KakaoTalk
    스프링
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
Caniro
C++ 의존 관계 (Dependency)
상단으로

티스토리툴바