-
카테고리
-
세부 분야
프로그래밍 언어
-
해결 여부
미해결
static 멤버 변수를 인스턴스 없이 호출할때
19.02.15 23:20 작성 조회수 255
0
강의 11분에서 설명하시는 질문입니다
아래는 제가 따라서 쓴 코드입니다.
include
using namespace std;class something
{
private:
static int s_value;
int m_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();
막상 빌드를 하려고 하는데
Cannot take the address of an rvalue of type 'int'
라고 뜹니다..... 우측값의 타입이 'int' 인 주소를 넣지 마세요 라는 말인 것 같은데..
어떻게 해결해야 할지 잘 모르겠습니다ㅠㅠ
답변을 작성해보세요.
답변 2