다음 코드가 있는데 제대로 작동합니다.Boost :: MPL로 왜 형식 지식이 사라지나요?
#include <boost\mpl\vector.hpp>
#include <boost\mpl\fold.hpp>
#include <boost\mpl\for_each.hpp>
#include <boost\mpl\inherit.hpp>
#include <boost\mpl\inherit_linearly.hpp>
#include <iostream>
using namespace boost::mpl::placeholders;
typedef boost::mpl::vector<short[2], long, char*, int> member_types;
template <typename T>
struct wrap
{
T value;
};
struct print
{
template <typename T>
void operator()(T) const
{
std::cout << typeid(T).name() << std::endl;
}
};
typedef boost::mpl::inherit_linearly<member_types, boost::mpl::inherit<wrap<_2>, _1> >::type Generate;
void main()
{
Generate generated;
print p;
std::cout << static_cast<wrap<int>&>(generated).value << std::endl;
boost::mpl::for_each<member_types>(p);
}
하지만 난 이런 식으로 수정할 경우 :
나는 오류 오류 C2440 얻을struct print
{
Generate generated;
template <typename T>
void operator()(T) const
{
std::cout << static_cast<wrap<int>&>(generated).value << std::endl;
}
};
: 'static_cast': [ 와 '& 랩'에 'const를 생성'에서 을 변환 할 수 있습니다 T = int
왜 메인에서 작동 하나, 모듈에 끼워 넣지는 않습니까? 유형 목록에 의해 구동되는 일련의 템플리트 함수에 의해 호출 될 유형 목록에 의해 작성된 데이터 값을 사용할 수있는 곳으로 데이터를 가져올 수 있습니까? 기본적으로 두 부분으로 유용한 무언가를 만드는 객체를 만드는 방법은 무엇입니까? 당신이 다음에 print
에 operator()
을 변경하는 경우
http://stackoverflow.com/questions/5790161/is -the-back-in-c-and-c-include-directives – fazo