469,635 Members | 1,934 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,635 developers. It's quick & easy.

"typedef typename" inside template

Hi!

I have a question for u guys!
I would like to use the c++ package ITK (www.itk.org) for internal handling och data and functions in a dataset3D class of mine!

I also want to use a base class to be able to use all kinds of datasets (2D/3D/4D...)
-----------------------------------------------------------
class dataset_base{
public:
virtual void printDataInfo()=0;
DATASET_TYPE type;
string file_path;
};
-----------------------------------------------------------

But I need some help with the template part of my dataset class....
Today my class looks like this...

------------------dataset3D.h-----------------------------------------
#ifndef _dataset3D_h_
#define _dataset3D_h_
#pragma once

#include <string>
#include <stdio.h>
#include <iostream>
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "dataset_base.h"
using namespace std;

template<class T>
class dataset3D: public dataset_base{
public:
typedef itk::Image<T,3> ImageType;
typedef typename ImageType::Pointer ImagePointerType;
typename int a;

dataset3D2(string filepath);
void printDataInfo();

private:
ImagePointerType theImage;

// int loadVolumeFromFile(string file);
ImagePointerType loadVolumeFromFile(string file);
};

#include "dataset3D2.cpp"
#endif

------------------dataset3D.cpp-----------------------------------------

//template<class T> int dataset3D2<T>::loadVolumeFromFile(string file){

template<class T> dataset3D2<T>::ImagePointerType dataset3D2<T>::loadVolumeFromFile(string file){ //(***)
cout<<"load_v("<<file<<")"<<endl;
}
return image.GetPointer();
}

-----------------------------------------------------------
But this gives following Compiler error in visual 7.1...
pointing at row (***)

Compiling...
dataset_array.cpp
c:\Joel\Code\ITKVTK\matrix\Src\Main\dataset3D2.cpp (28) : warning C4346: 'dataset3D2<T>::ImagePointerType' : dependent name is not a type
prefix with 'typename' to indicate a type
.....
.....

What is it that I am doing wrong!
I thought that (typedef typename was enough...)
Thanks in advance...

// Joel
Sep 23 '05 #1
1 18502
Hey
It's been a long time since you posted this, but just in case you were wondering:

where you use
typedef typename ImageType::Pointer ImagePointerType;
(or any type name combination)
to use it as a return type for a function, you would need to specify that this is a typename, or in your example
template<class T>
typename dataset3D2<T>::ImagePointerType
dataset3D2<T>::loadVolumeFromFile(string file){ //(***)
etc. etc.
Notice the placement of the "typename" before the actual typenamed name
Mar 29 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Michael Olea | last post: by
reply views Thread by Gary | last post: by
reply views Thread by mailforpr | last post: by
8 posts views Thread by Mohammad Omer Nasir | last post: by
8 posts views Thread by cman | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.