Skip to main content
GameDev.net gamedev.net
🔒 Locked

Template compiler errors

Started by Mathius20 May 17, 2006 at 10:38 PM 6 replies 2k views
Original Post
Mathius20
Mathius20
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
jflanglois
jflanglois
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.
Mathius20
Mathius20
Hmmm, im not using any vectors but i am using some iterators.



list::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?)
jflanglois
jflanglois
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]
Mathius20
Mathius20
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.
Mathius20
Mathius20
Sweet it works now. Well now i can actually see the errors in my code. Thanks a lot!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.