Hi There!

Quick, probably dumb question but I have the following snippet

template<typename T>
	class Natural : public ArbitraryNumber{
		std::vector<T> mVal;
		std::vector<T>::iterator mIter;

instantiated with

math::Natural<long double> z;

in my main module. Visual C++ dislikes this. When I put this in:

typename std::vector<typename T>::iterator mIter;

...it works fine. Is this just VC being an incredible pain or is there a good reason for this? I should probably try it with another compiler but it took me too much time to 'fix' this...now I'm just irritated ;P

Thanx!
Sean

>Visual C++ dislikes this.
Any conforming C++ compiler should dislike it.

>Is this just VC being an incredible pain or is there a good reason for this?
There's a good reason. Without going into excessive detail, because std::vector<T>::iterator is a qualified name that's dependent on the template argument T, there's an ambiguity there where the compiler could recognize the line as either a declaration or a statement and both are equally good choices. The typename keyword is for disambiguation so that you can say "yes, this really is a type".

Templated classes denote incomplete types and you can specialize a particular case to have a completely different definition than the general case.

What's the guarantee that long double isn't a specialized case in the vector class that doesn't have an inner iterator class?

I'm not sure when it is resolved (most likely at compile time) but when typename is used, like Narue stated you are telling the compiler it is a type that exists within the case of vector<long double>.

Thank you very much folks...just hadn't really run into that particular issue before.

Thanx...
Sean

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.