Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Problem with typedefs in Templates

wilfried_horn
Beginner
334 Views
The following code causes an error when instantiated:

(smaller and bigger are replace by [ and ] since the forum complains about html tags if I use them)

template [class PairIterator]
class project1st_iterator
{
public:
typedef typename PairIterator::value_type::first_type value_type;
};

Specifically the compiler tells me that the second mention of "PairIterator" should be a class. But it is defined as a class through the template.
The code works with gcc and I don't know either a solution or a workaround. I would be thankful for any idea!

Cheers!

Wilfried
0 Kudos
2 Replies
mikhkup
Beginner
334 Views
Maybe you should use more 'typename' decls, at it's unclear to compilerwhat PairIterator::value_type is.
template [class PairIterator]
class project1st_iterator
{
public:
typename PairIterator::value_type;
typename PairIterator::value_type::first_type;
typedef PairIterator::value_type::first_type value_type;
};
I can't test it since i'm working with version 7.0 of intel compiler, it compiles your code OK.
0 Kudos
Judith_W_Intel
Employee
334 Views
I tried recreating the error message with the limited code snippet you posted and was unable to, i.e. this compiles fine with the Intel compiler:
template
struct Base {
typedef T1 first_type;
};
template
struct Iter {
typedef Base value_type;
};
template
class project1st_iterator
{
public:
typedef typename PairIterator::value_type::first_type value_type;
};
project1st_iterator > p;
Please post a more complete example that reproduces the problem and then we can help you. Also which version of the compiler were you using (use icpc -V)?
thanks
Judy
0 Kudos
Reply