-4
템플릿 클래스를 입력 파라미터로 받아들이는 템플릿 함수를 작성하고 싶습니다.템플릿 클래스를 받아들이는 템플릿 함수
template<class T>
void Function(T Input)
{
}
위와 같은 것입니다. 클래스는 Template 클래스가 될 수 있습니까 ?? 예인 경우 어떻게 작성합니까? 이 작업을 수행하는 동안 오류가 발생했습니다. 이것 좀 도와주세요. 사전에 감사
편집 :
다음과 같은 오류template<class T>
void ReadImage(T InputImage)
{
InputImage::Pointer InputImagePointer = InputImage::New();
typedef itk::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer ImageFileReader = ReaderType::New();
ImageFileReader->SetFileName(FileName);
ImageFileReader->Update();
}
int main()
{
std::string FileName = "NameOfTheFile.mhd";
std::ifstream InputFile(FileName, ios_base::in);
while (!InputFile.eof())
{
string InputData;
//getline(InputFile, InputData);
InputFile >> InputData;
if (InputData == "ElementType")
{
//cout << "Came Here" << endl;
InputFile >> InputData;
InputFile >> InputData;
if (InputData == "MET_UCHAR")
{
typedef unsigned char ImagePixelType;
typedef itk::Image<ImagePixelType, 3> InputImageType;
ReadImage(InputImageType);
}
else if(InputData == "MET_USHORT")
{
typedef unsigned char ImagePixelType;
typedef itk::Image<ImagePixelType, 3> InputImageType;
ReadImage(InputImageType);
}
}
}
내가 얻을 : 오류 1 오류 C2275 : '에 imagetype': 내가 호출 할 때
오류가 표현으로 이러한 유형의 불법 사용을 발생 else 조건에있는 ReadImage() 함수
당신은 무엇을 의미합니까 * "클래스 템플릿 클래스가 될 수 있습니다"*? 그것은 이미 클래스 템플릿의 전문화 일 수 있습니다. 어쩌면 당신은 특정한 수의 논증을 추론하고 싶을 것입니다. –
실패한 코드와 컴파일러가 준 정확한 오류를 보여 주어 사람들이하고 싶은 일에 대해 더 잘 이해하고 해결하도록 도와주세요. – Mat
@Mat : 오류를 던지는 코드를 업데이트했습니다. – Barry