dev-ima
이마의 개발 블로그
dev-ima
전체 방문자
오늘
어제
  • 분류 전체보기 (16)
    • deeplearning study (4)
    • toy project (3)
    • algorithm study (0)
    • Portfolio (0)
    • Design Pattern (1)
    • Computer Vision (3)
    • c++ (4)
    • MLops (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • TITANIC
  • image Enhancement
  • machine learning
  • static member
  • 정적멤버변수
  • Face Recognition
  • 비지도
  • static member method
  • DETR
  • Python
  • kaggle
  • 머신러닝
  • C++
  • UML 다이어그램
  • cv
  • ML workflow
  • MLops
  • Unsupervised
  • ML시스템
  • UW-Madison GI Tract Image Segmentation
  • Recognition
  • Data의 종류
  • static member variable
  • Object detection
  • DEEPLEARNING
  • Computer Vision
  • instance segmetation
  • ML system
  • 딥러닝 시스템
  • 정적멤버함수

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
dev-ima

이마의 개발 블로그

c++

정적 멤버 함수(static member variable)

2023. 4. 5. 23:14

정적 멤버

  • class에는 속하지만, 객체 별로 할당되지 않고 클래스의 모든 객체가 공유하는 멤버
  • 즉, 클래스의 모든 객체에 대해 하나의 데이터만 유지됨
#include<iostream>
using namespace std;

class Something{
public:
	static int s_value;
};

int Something::s_value = 1024;

int main(){
	Something s1;
    cout << s1.s_value << endl;
    return 0;
}

정적 멤버 함수

  • 클래스의 객체를 생성하지않고 호출 가능
  • 객체를 생성하지 않으므로, this 포인터를 가지지 않음
  • 특정 객체에 포함되지 않으므로, 정적 멤버 변수만 사용가능
#include <iostream>
using namespace std;

class Something{
private:
    static int s_value;
    

public:
    static int getValue(){
        return s_value;
    }
    int temp(){
        return this->s_value;
    }
};

int Something::s_value = 1024;

int main(){
    cout << Something::getValue() <<endl;

    Something s1, s2;
    cout << s1.getValue() << endl;

    int (Something::*fptr1)() = &Something::temp;

    cout << (s2.*fptr1)() <<endl;

    int (*fptr2)() = &Something::getValue;

    cout << (*fptr2)() << endl;

    return 0;
}

'c++' 카테고리의 다른 글

메모리의 stack영역, heap영역  (0) 2023.02.16
함수 포인터  (0) 2023.02.15
함수 오버로딩  (0) 2023.02.11
    'c++' 카테고리의 다른 글
    • 메모리의 stack영역, heap영역
    • 함수 포인터
    • 함수 오버로딩
    dev-ima
    dev-ima

    티스토리툴바