이상한 범위 확인 연산자가 있는 C++ typedef (C++ typedef with strange scope resolution operator)


문제 설명

이상한 범위 확인 연산자가 있는 C++ typedef (C++ typedef with strange scope resolution operator)

C++ 코드를 이식해야 하고 다음과 같은 이상한 typedef를 찾았습니다.

typedef uint32_t SomeClassName::* ptr;

대상 컴파일러는 MSVC++입니다. 내가 이해하는 한, 이것은 ptr이라는 uint32_t*에 대한 별칭을 생성합니다. SomeClassName::이 있는 부분은 아무 쓸모도 없으며 호환되는 C++ 컴파일러에서 오류로 처리해야 합니다. 내가 맞거나 틀릴까요?

또한 특이한 범위 확인 연산자를 찾았습니다. SO에 대한 질문으로 이 질문에 답할 수 있지만 확실하지 않습니다.


참조 솔루션

방법 1:

This is a pointer to member. Specifically a variable of type ptr can point to any uint32_t data member of SomeClassName. It can be used like this:

struct Foo {
    int a;
    int b;
    float c;
};

Foo foo;
int Foo::* ptr;

ptr = &Foo::a;
foo.*ptr = 10; //Set foo.a to 10

ptr = &Foo::b;
foo.*ptr = 15; //Set foo.b to 15

//ptr = &Foo::c; //Won't compile

(by actualKevin)

참조 문서

  1. C++ typedef with strange scope resolution operator (CC BY‑SA 2.5/3.0/4.0)

#C++ #scope #standards #visual-c++ #typedef






관련 질문

파일의 암호화/복호화? (Encryption/ Decryption of a file?)

이상한 범위 확인 연산자가 있는 C++ typedef (C++ typedef with strange scope resolution operator)

개체 배열 매개변수--오류: '문자' 필드에 불완전한 유형이 있습니다. (Object array parameter--error: field ‘letters’ has incomplete type)

C++에서 메모리 삭제 (Deleting memory in c++)

C++ 프로그램을 실행할 수 없습니다. No se ejecuta el programa (C++ i can't run a program. No se ejecuta el programa)

컴파일 시 변수의 이름과 수명 (Name and lifetime of variables at compile time)

control-c 후 Visual Studio 콘솔 프로그램 충돌 (visual studio console program crashes after control-c)

멤버 변수에 std::enable_if 또는 유사한 메서드 사용 (Using std::enable_if or similar method on member variable)

ifstream input_file(filename); (I am receiving an error "no matching function to call" in the line ifstream input_file(filename);)

ESP8266에서 잠시 실행하면 JsonData 크기가 0이 됩니다. (JsonData size becomes zero after awhile of running in ESP8266)

합에 대한 속도 문제(제수의 합) (Speed problem for summation (sum of divisors))

벡터 벡터에서 하위 벡터의 첫 번째 값을 찾기 위해 begin() 및 end() 반복기의 범위를 지정하는 방법은 무엇입니까? (How to specify a range for begin() and end() iterators to find first value of sub vector in a vector of vectors?)







코멘트