Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error in VC++ include-file

Status
Not open for further replies.

Flay

Programmer
Sep 13, 2006
8
NL
I'm trying to build a parser-program, but when i compile my programm it gives me this error:
c:\program files\microsoft visual studio\vc98\include\map(27) : error C2143: syntax error : missing ';' before 'namespace'

The line where the error seems to be contains the following code:

_STD_BEGIN


Anyone have any idea, why i get this error? it is an include-file from Visual C++ itself, so i don't think it's a fault from my side, or am i wrong?
 
Do you have the latest Visual Studio service pack?

If you trace the error up until you get to your code, what does your code look like?
 
I'm using Visual C++ 6.0 because i'm using the MTL-library in my project. There is not yet a working version of MTL available for newer versions of Visual C++.
 
I believe the latest service pack for VC++ 6.0 is SP5.
 
i did just install service pack 5 for Visual C++ 6.0, but i still got the same error-message.
 
Try doing a Build->Rebuild All.

Can you post some of your code around the area where the map is being used?

What files are you including and in what order?
 
i got in a file mkv.cpp a function called calculate,
in there i got a variable TV from the type MAP (MAP is defined as:
typedef map <unsigned int, list<Vec*>* > MAP; )

To let the program know that "map <unsigned int, list<Vec*>* >" exists i have the following include
#include <map>.
This typedef and include are inside mkv.h

The only include i got in mkv.cpp is #include "mkv.h"
All the includes+typedefs in mkv.h are:
#include "../parse/comm.h"
#include <string>
#include <fstream>
#include <list>
#include <map>
#include <mtl/matrix.h>
#include <mtl/utils.h>
#include <mtl/mtl.h>

using namespace std;
using namespace mtl;

typedef matrix <double, rectangle<>, compressed<>, row_major>::type SparseMat;
typedef matrix <double, rectangle<>,dense<> >::type Vec;
typedef dense1D <double> P;
typedef map <unsigned int, list<Vec*>* > MAP;

This is some code in the calculate function where i use the variable of the MAP-type:

//calculate for time=0 to j*time_skip
copy(svec[0],CurrentP); //set CurrentP to start vector
for (j=0;j<=(last_time/time_skip);j++){
//adjust CurrentP for test exec
if (TV[j]!=0){
for (t=TV[j]->begin();t!=TV[j]->end();++t){
//remove
ele_mult(CurrentP,(**t)[0],tmpP);
add(CurrentP,scaled(tmpP,-1.0),CurrentP);

redis=sum(tmpP);
//receive
set_value(tmpP,redis);
ele_mult(tmpP,(**t)[1],tmpP);
add(CurrentP, tmpP, CurrentP);
}

}

ele_mult() and add() are functions from the MTL-library, i did not write these myself.

But i'm still wondering the error has something to do with my code, because the error is inside that map-file in the directory
c:\program files\microsoft visual studio\vc98\include\
 
It's virtually impossible that the error is actually in the VC++ file, otherwise somebody would have found that problem by now.

I gotten several errors that point to VC++ include files; but when I move backwards to the parts of my code where I use that STL class, I usually see where I did something wrong.

Sometimes it even helps to just change the order of the #include directives.
I usually put all the built-in headers first, then put my own afterwards.

Also, putting the using namespace std; in your header file isn't always a good idea since it can cause namespace conflicts with other files that include your header.

BTW, did this code ever compile in the past and now isn't compiling after making some changes, or is this the first time you've tried compiling it?
 
The only place where i am using that MAP-part is in the code i copied in my previous post. I tried with moving the "using namespace std;" to my .cpp file, but this doesn't change the number of the errors or the errors. When i moved "using namespace mtl;" also to my .cpp file i had many many errors, after putting mtl:: in front of all the neccesary items i again had the same amount of errors as allways.

I also changed the order of the #include directives as you say, doesn't make any difference.

This code has compiled before, i got this code from a colleague who has built this programm. At his workstation everything compiles and runs fine (but he is using a German version of Visual C++ 6.0). He gave me the code so i could continue working on it.
So practicly saying, i'm using an other language-version of Visual C++ 6.0 on an other workstation.
But can that be the problem?
 
The language of Visual Studio shouldn't matter.

I couldn't see where you were declaring a MAP variable in the code you posted. All I saw was the MAP typedef.

Can you post all occurances of "map", "MAP" or any other typedefed variables that use map.

Did your colleague give you the .dsp & .dsw files too or just the .h & .cpp files?

Do you get different results if you build Release vs. Debug?
 
All occurances of "map" and "MAP" are:

In mkv.h:
Code:
#include <string>
#include <fstream>
#include <list>
[b]#include <map>[/b]
#include "../parse/comm.h"
#include <mtl/matrix.h>
#include <mtl/utils.h>
#include <mtl/mtl.h>

using namespace std;
using namespace mtl;

typedef matrix <double, rectangle<>, compressed<>, row_major>::type  SparseMat;
typedef matrix <double, rectangle<>,dense<> >::type Vec;
typedef dense1D <double> P;
[b]typedef map <unsigned int, list<Vec*>* > MAP;[/b]

and in mkv.cpp:

inside the function int calculate()
Code:
     [b]MAP TV;[/b]
	list<Vec*>::iterator t;
	Q testq;
	

	if ([b]init_redis(TV, testq)[/b]){  //initializes the redistributions
		error.print("NO TESTS TO EXECUTE",MNR);
	} 
	else
	{
		//print_test_mat(TV);/*DEBUG*/
		print_test(testq);
	}
	
	cout<<"+++MODEL OK+++"<<endl;
	cout<<"+++CALCULATING+++"<<endl;

	//open files for output
	ofstream* out_plt;
	out_plt=new ofstream(plt);
	out_plt->setf(ios::scientific);
	*out_plt<<model_desc()<<endl;

	double redis;

//calculate for time=0 to j*time_skip
	copy(svec[0],CurrentP); //set CurrentP to start vector
	for (j=0;j<=(last_time/time_skip);j++){
	//adjust CurrentP for test exec
		[b]if (TV[j]!=0){
			for (t=TV[j]->begin();t!=TV[j]->end();++t){[/b]
				//remove
				ele_mult(CurrentP,(**t)[0],tmpP);
				add(CurrentP,scaled(tmpP,-1.0),CurrentP);
				//print_vector(CurrentP);print_vector(tmpP);
				redis=sum(tmpP);
				//receive
				set_value(tmpP,redis);
				ele_mult(tmpP,(**t)[1],tmpP);//print_vector(tmpP);
				add(CurrentP, tmpP, CurrentP);//print_vector(CurrentP);
			}
				
		}

Everything what the function-call init_redis(TV, testq) does, is clearing the whole vector, and fill it with the information the parser gets out of the input-file.

My colleague gave me all the files, including the .dsp and .dsw files.
There are no different results when i build Release or Debug, still the same errors occur.
 
I tried to find out when my errors appear,

I did make a new project, so i have a totally empty main-function (win32 console app).
I can do everything i want, but when i put the line "#include <map>" inside my file the error comes up again.
 
The STL header files in VC++ 6.0 was pretty broken. Try using this header file and include it in your project instead of <map>
Code:
// stl_map.h:  This will include the <map> header file without any errors.
//
// Copyright 2004-2005 by Chris Just.  All Rights Reserved.
/////////////////////////////////////////////////////////////////////
#ifndef STL_MAP_HEADER
#define STL_MAP_HEADER

#if defined( _MSC_VER ) && (_MSC_VER <= 1200)	// 1200 = MSVC 6.0.
// This warning must be permanently disabled.
#	pragma warning(disable: 4503)	// 'decorated name length exceeded, name was truncated.

#	pragma once
#	pragma warning(push, 3)
#	pragma warning(disable: 4018)	// signed/unsigned mismatch.
#	pragma warning(disable: 4100)	// unreferenced formal parameter.
#	pragma warning(disable: 4245)	// conversion from 'type1' to 'type2', signed/unsigned mismatch.
#	pragma warning(disable: 4512)	// 'class' : assignment operator could not be generated.
#	pragma warning(disable: 4663)	// C++ language change: to explicitly specialize class template 'vector'.
#	pragma warning(disable: 4710)	// 'function' : function not inlined.
#	pragma warning(disable: 4786)	// identifier was truncated to 'number' characters in the debug information.

// BUG: C4786 Warning Is Not Disabled with #pragma Warning
// STATUS: Microsoft has confirmed this to be a bug in the Microsoft product. 
// This warning can be ignored. This occured only in the <map> container.

#	include <map>

#	pragma warning(pop)
#else	// UNIX
#	include <map>
#endif	// _MSC_VER <= 1200

#endif	// STL_MAP_HEADER
 
Thanks for your great help, cpjust, but i still got the same error, there must something else going on.

But thanks anyway for you help!!
 
You could download VC++ 2005 Express (it's free) and try that. If it is a bug in the 6.0 <map> file, it should compile with 2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top