멤버에 대한 포인터에 액세스할 수 없습니다.왜?
-
05-07-2019 - |
문제
다음 코드를 고려해보세요.
template<class T, class F> struct X {};
template<class T, class F, T F::* m> struct Y {};
struct Foo {
int member;
typedef X<int, Foo> x_type; // works well
typedef Y<int, Foo, &Foo::member> y_type; // ERROR
};
typedef Y<int, Foo, &Foo::member> y_type2; // OK
컴파일러가 오류를 생성하는 이유는 무엇입니까?(VS2008)
새로운
나는 이 버그를 다음에 게시했습니다. connect.microsoft.com.
해결책 2
이것은 벌레
다른 팁
나는 같은 문제를 우연히 발견했습니다.멤버에 대한 포인터 템플릿 인수에 대한 지원은 VC++에서 여전히 제한되어 있습니다(참조: 버그 보고서).
내 경우에는 템플릿 함수 i.s.o를 사용하여 이 문제를 해결할 수 있었습니다.템플릿 클래스:
template< typename Class > struct CMemberDumper {
Class& object;
template< typename M > void visit_member( M C::*pm ) {
std::cout << object.*pm;
}
};
제휴하지 않습니다 StackOverflow