Sign in to follow this  
danto

strange std compile errors

Recommended Posts

danto    154
I have recently had a strange compile error that I cannot seem to figure out. It started propagating on some of my projects for no reason...even projects that I have not changed. At first i thought it was just a random element, but it seems to be tied to mscv++ 7.1 and iostream and fstream. Now I could be wrong on this but that is what I have come down to. Now the errors I am getting is as follows:
g:\VC98\Include\UTILITY(81) : warning C4346: '_It::iterator_category' : dependent name is not a type
        prefix with 'typename' to indicate a type
        g:\VC98\Include\UTILITY(84) : see reference to class template instantiation 'std::iterator_traits<_It>' being compiled
g:\VC98\Include\UTILITY(81) : error C2146: syntax error : missing ';' before identifier 'iterator_category'
g:\VC98\Include\UTILITY(81) : error C2501: 'std::iterator_traits<_It>::iterator_category' : missing storage-class or type specifiers
g:\VC98\Include\UTILITY(82) : warning C4346: '_It::value_type' : dependent name is not a type
        prefix with 'typename' to indicate a type
g:\VC98\Include\UTILITY(82) : error C2146: syntax error : missing ';' before identifier 'value_type'
g:\VC98\Include\UTILITY(82) : error C2501: 'std::iterator_traits<_It>::value_type' : missing storage-class or type specifiers
g:\VC98\Include\UTILITY(83) : warning C4346: '_It::distance_type' : dependent name is not a type
        prefix with 'typename' to indicate a type
g:\VC98\Include\UTILITY(83) : error C2146: syntax error : missing ';' before identifier 'distance_type'
g:\VC98\Include\UTILITY(83) : error C2501: 'std::iterator_traits<_It>::distance_type' : missing storage-class or type specifiers
g:\VC98\Include\UTILITY(224) : warning C4348: 'std::istreambuf_iterator' : redefinition of default parameter : parameter 2
        g:\VC98\Include\UTILITY(279) : see declaration of 'std::istreambuf_iterator'
g:\VC98\Include\UTILITY(226) : warning C4346: '_Tr::off_type' : dependent name is not a type
        prefix with 'typename' to indicate a type
        g:\VC98\Include\UTILITY(279) : see reference to class template instantiation 'std::istreambuf_iterator<_E,_Tr>' being compiled
g:\VC98\Include\UTILITY(226) : error C2923: 'std::iterator' : '_Tr::off_type' is invalid as template argument '#3', type expected
g:\VC98\Include\UTILITY(231) : warning C4346: '_Tr::int_type' : dependent name is not a type
        prefix with 'typename' to indicate a type
g:\VC98\Include\UTILITY(231) : error C2146: syntax error : missing ';' before identifier 'int_type'
g:\VC98\Include\UTILITY(231) : error C2501: 'std::istreambuf_iterator<_E,_Tr>::int_type' : missing storage-class or type specifiers
g:\VC98\Include\UTILITY(289) : warning C4348: 'std::ostreambuf_iterator' : redefinition of default parameter : parameter 2
        g:\VC98\Include\UTILITY(318) : see declaration of 'std::ostreambuf_iterator'
g:\VC98\Include\XSTRING(25) : warning C4346: '_A::size_type' : dependent name is not a type
        prefix with 'typename' to indicate a type
        g:\VC98\Include\XSTRING(597) : see reference to class template instantiation 'std::basic_string<_E,_Tr,_A>' being compiled
g:\VC98\Include\XSTRING(25) : error C2146: syntax error : missing ';' before identifier 'size_type'
g:\VC98\Include\XSTRING(25) : error C2501: 'std::basic_string<_E,_Tr,_A>::size_type' : missing storage-class or type specifiers
g:\VC98\Include\XSTRING(26) : warning C4346: '_A::difference_type' : dependent name is not a type
        prefix with 'typename' to indicate a type
g:\VC98\Include\XSTRING(26) : error C2146: syntax error : missing ';' before identifier 'difference_type'
g:\VC98\Include\XSTRING(26) : error C2501: 'std::basic_string<_E,_Tr,_A>::difference_type' : missing storage-class or type specifiers
g:\VC98\Include\XSTRING(27) : warning C4346: '_A::pointer' : dependent name is not a type
        prefix with 'typename' to indicate a type
g:\VC98\Include\XSTRING(27) : error C2146: syntax error : missing ';' before identifier 'pointer'
g:\VC98\Include\XSTRING(27) : error C2501: 'std::basic_string<_E,_Tr,_A>::pointer' : missing storage-class or type specifiers
g:\VC98\Include\XSTRING(28) : warning C4346: '_A::const_pointer' : dependent name is not a type
        prefix with 'typename' to indicate a type
g:\VC98\Include\XSTRING(28) : error C2146: syntax error : missing ';' before identifier 'const_pointer'
g:\VC98\Include\XSTRING(28) : error C2501: 'std::basic_string<_E,_Tr,_A>::const_pointer' : missing storage-class or type specifiers
g:\VC98\Include\XSTRING(29) : warning C4346: '_A::reference' : dependent name is not a type
        prefix with 'typename' to indicate a type
g:\VC98\Include\XSTRING(29) : error C2146: syntax error : missing ';' before identifier 'reference'
g:\VC98\Include\XSTRING(29) : error C2501: 'std::basic_string<_E,_Tr,_A>::reference' : missing storage-class or type specifiers
g:\VC98\Include\XSTRING(30) : warning C4346: '_A::const_reference' : dependent name is not a type
        prefix with 'typename' to indicate a type
g:\VC98\Include\XSTRING(30) : error C2146: syntax error : missing ';' before identifier 'const_reference'
g:\VC98\Include\XSTRING(30) : error C2501: 'std::basic_string<_E,_Tr,_A>::const_reference' : missing storage-class or type specifiers
g:\VC98\Include\XSTRING(31) : warning C4346: '_A::value_type' : dependent name is not a type
        prefix with 'typename' to indicate a type
g:\VC98\Include\XSTRING(31) : error C2146: syntax error : missing ';' before identifier 'value_type'
g:\VC98\Include\XSTRING(31) : error C2501: 'std::basic_string<_E,_Tr,_A>::value_type' : missing storage-class or type specifiers
g:\VC98\Include\XSTRING(32) : warning C4346: '_A::pointer' : dependent name is not a type
        prefix with 'typename' to indicate a type
g:\VC98\Include\XSTRING(32) : error C2144: syntax error : 'std::iterator' should be preceded by ';'
g:\VC98\Include\XSTRING(32) : error C2698: the using-declaration for 'pointer' cannot co-exist with the existing using-declaration for 'pointer'
g:\VC98\Include\XSTRING(32) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Now this is what I am trying to comile... the project I am working on is far more complex but as a test i slapped together this quick example which use to compile fine in vc++ 7.1 but now does not.
#include <fstream>
#include <iostream>


using namespace std;

void main()
{
	fstream file;
	file.open("test.txt", ios::out);

	file << "example" << endl;

	file.close();

}
I also tried compiling the code under vc++ 6 and it compiled fine and ran fine. This is a strange because my larger projects have started running into this compile error as well. For instance I was working on my project and created a new class and compiled fine...went to implement the class in another and started getting the compile errors. I back out and commented out the implementation, but the errors remained. On the same code that compiled fine a moment ago! I have tried un-installing and re-installing msvc++ 7.1 to no avail. I have searched through numerous google search pages trying to find anything on the probelm. The closest I got was the exact same errors and the only response saying it looked like a compiler glitch, but he didn't have an answer. I also searched throught the msdn database and found nothing. Please, if anyone has any idea please help. Thanks.

Share this post


Link to post
Share on other sites
snk_kid    1312
Quote:
Original post by danto

g:\VC98\Include\UTILITY(81) : warning C4346: '_It::iterator_category' : dependent name is not a type
prefix with 'typename' to indicate a type
g:\VC98\Include\UTILITY(84) : see reference to class template

.....
I also tried compiling the code under vc++ 6 and it compiled fine and ran fine.
.....


I've highlighted a key issue for you, VC++ 7.1 is including VC++ 6.0 headers not it's own, hence compiles fine on VC++ 6.0 because it's non-standard compliant and defunct while VC++ 7.1 is 98% standard compliant.

By the way that error message is caused by template/generic code, when you refer to nested types that depends on a template type parameter the compiler cannot tell if your referring to a type or static member the correct method to handle this is to use *typename* keyword to indicate a nested type instead of a static member but VC++ 6.0 is wrong so it's implementation of standard library is wrong (not to mention broken) and VC++ 7.1 is wright!

Share this post


Link to post
Share on other sites
danto    154
You are my new god! I totally didn't see that and was stupid enough to include the vc98 headers in the friggin project. I removed that and the errors went away. Praise be to snk_kid! THANK YOU!

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