Sign in to follow this  
Mathius20

Template compiler errors

Recommended Posts

Mathius20    122
Hey, I just started using templates with my project, and when I compile it pulls up 27 errors, but all of the errors are in the header files that contain the templates.(xstring and utility) C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(81) : warning C4346: '_It::iterator_category' : dependent name is not a type prefix with 'typename' to indicate a type C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(84) : see reference to class template instantiation 'std::iterator_traits<_It>' being compiled C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(81) : error C2146: syntax error : missing ';' before identifier 'iterator_category' C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(81) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(82) : warning C4346: '_It::value_type' : dependent name is not a type prefix with 'typename' to indicate a type C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(82) : error C2146: syntax error : missing ';' before identifier 'value_type' C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(82) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(83) : warning C4346: '_It::distance_type' : dependent name is not a type prefix with 'typename' to indicate a type C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(83) : error C2146: syntax error : missing ';' before identifier 'distance_type' C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(83) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(224) : warning C4348: 'std::istreambuf_iterator' : redefinition of default parameter : parameter 2 C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(279) : see declaration of 'std::istreambuf_iterator' C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(226) : warning C4346: '_Tr::off_type' : dependent name is not a type prefix with 'typename' to indicate a type C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(279) : see reference to class template instantiation 'std::istreambuf_iterator<_E,_Tr>' being compiled C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(226) : error C2923: 'std::iterator' : '_Tr::off_type' is not a valid template type argument for parameter '_D' C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(226) : error C2955: 'std::iterator' : use of class template requires template argument list C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(71) : see declaration of 'std::iterator' C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(231) : warning C4346: '_Tr::int_type' : dependent name is not a type prefix with 'typename' to indicate a type C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(231) : error C2146: syntax error : missing ';' before identifier 'int_type' C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(231) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(289) : warning C4348: 'std::ostreambuf_iterator' : redefinition of default parameter : parameter 2 C:\Program Files\Microsoft Visual Studio\VC98\Include\utility(318) : see declaration of 'std::ostreambuf_iterator' C:\Program Files\Microsoft Visual Studio\VC98\Include\xstring(25) : warning C4346: '_A::size_type' : dependent name is not a type prefix with 'typename' to indicate a type C:\Program Files\Microsoft Visual Studio\VC98\Include\xstring(597) : see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>' being compiled are some of the errors. I have no idea what the problem could be. Thanks

Share this post


Link to post
Share on other sites
jflanglois    1020
We're probably going to have to see some code, but it seems that you are not using typename with a dependant name:

template< class T >
struct Test {
  std::vector< T >::iterator MyIterator;
};


should be:

template< class T >
struct Test {
  typename std::vector< T >::iterator MyIterator;
};


[edit] Hmmm, yes. Post some of your code.


jfl.

Share this post


Link to post
Share on other sites
Mathius20    122
Hmmm, im not using any vectors but i am using some iterators.



list<IMMObject *>::iterator it=DeadObjects.begin();it != DeadObjects; it++)

I never use typename, and I also dont use std(do you have to if you use using namespace std?)

Share this post


Link to post
Share on other sites
jflanglois    1020
I used vector by means of an example, and no you do not need to prefix it with std:: if you have already imported the namespace.

I think it would be much easier if you showed the code that causes this problem.

Also, if I'm not mistaken, that is Visual C++ 6. I remember VC6 having trouble with templates. I highly recommend that you upgrade to a newer version. Visual C++ 2005 Express Edition is free.


jfl.

[Edited by - jflanglois on May 17, 2006 11:19:22 PM]

Share this post


Link to post
Share on other sites
Mathius20    122
Well im using 2005 but im using the vc++ 6 headers...that may be a problem^_^ and the debugger doesnt show any errors in my code. I used the old headers because the 2005 didnt have windows.h etc.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this