1
템플릿하는 것은 최소한의 예를오류가 여기에 클래스
#include <iostream>
template<typename T>
struct MyClass{
T value;
};
template<typename T, template<typename> class Class>
void foo(Class<T>& myClass){
myClass.value=0;
};
int main(){
MyClass<double> myclass;
foo<double, MyClass<double>>(myclass);
return 0;
}
이 코드는 컴파일되지 않습니다이며, 오류를 제공
error: no instance of function template "foo" matches the argument list
argument types are: (MyClass<double>)
foo<double, MyClass<double>>(myclass);
내가 쓰고 싶은 이유 함수는 CPU와 GPU간에 데이터를 전송하는 함수를 작성하고 싶습니다. 함수는 다음과 같습니다.
template<typename Scalar, template<typename > class Host,
template<typename> class Device>
void copyFromHostAsync(const Host<Scalar> &host, Device<Scalar> &device, cudaStream_t stream) {
assert(host.rows() == device.rows());
assert(host.cols() == device.cols());
cudaMemcpyAsync(device.getPtr(), host.getPtr(), sizeof(Scalar) * host.rows() * host.cols(),
cudaMemcpyHostToDevice, stream);
}
기본 스칼라 유형이 동일하도록 매개 변수로 템플릿 기반 클래스를 사용하고 싶습니다.
도움이 필요합니다.
그건 사실입니다! 고마워요! –