다음 TestClass
작품 :멤버 함수 템플릿을 사용하여 부스트 : : 기능
#include <iostream>
#include <boost/function.hpp>
#include <boost/bind.hpp>
void ext_fun(const float f, int i)
{
std::cout << f << '\t' << i << std::endl;
}
template <typename T>
class TestClass
{
public:
boost::function <void (const T)> test_fun;
};
int main()
{
TestClass<float> tt;
tt.test_fun = std::bind(ext_fun, std::placeholders::_1, 10);
tt.test_fun(2.1);
return(0);
}
그러나, 나는, 즉 멤버 함수 템플릿으로 test_fun
을 정의 할 수
class TestClass
{
public:
template <typename T> boost::function <void (const T)> test_fun;
};
그러나 만약 같은 것을 선호 나는 이렇게 컴파일러 오류가 발생한다 : "오류 : 데이터 멤버 'test_fun'은 멤버 템플릿이 될 수 없다.
멤버 펑크를 정의 할 수 있는가? 이온 템플릿을 사용하여 boost::function
? 그렇다면 어떻게?
--Matteo
죄송합니다. 의미가 없습니다. '기능 템플릿'의 의미가 아닙니다. 당신은 "struct Foo {int a;};를'struct Foo {template T a;};'"로 변환 할 수 있습니까? –
@Kerrek SB 나는 첫 번째 예제 [here] (http://msdn.microsoft.com/en-us/library/swta9c6e%28VS.80%29.aspx) 나 [여기에있는 질문 ] (http://stackoverflow.com/questions/972152/how-to-create-a-template-function-within-a-class-c),하지만 부스트 :: 함수를 사용하여 –