Visual Studio .NET Help Needed

grrr… I have a project due in the morning, but VS .NET is throwing…odd… errors at me that I’ve never seen before. Anyone have any ideas?

(Note: the errors are coming from header files included with VS .NET 2003; not my own source.)

c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\math.h(36): error C2143: syntax error : missing ‘;’ before ‘string’
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\math.h(36): error C2143: syntax error : missing ‘;’ before ‘string’
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\math.h(36): fatal error C1004: unexpected end of file found
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\math.h(36): fatal error C1004: unexpected end of file found

Except this one, which is coming from my code:

c:\Documents and Settings\Owner\My Documents\Visual Studio Projects\ComplexNumber\ComplexNumber.cpp(5): error C2143: syntax error : missing ‘;’ before ‘using’
c:\Documents and Settings\Owner\My Documents\Visual Studio Projects\ComplexNumber\ComplexNumber.cpp(5): error C2143: syntax error : missing ‘;’ before ‘using’

Now, the only code up to that point is:

#include <iostream>
#include “ComplexNumber.h”
//#include <math.h>

using namespace std;

And earlier, that same code bit was showing an error with “yvals.h,” which is an included VS .NET file.

Anyone have any suggestions? Could it be that just my math.h and yvals.h files are corrupted?

Thanks in advance!

Why is ComplexNumber.h in quotes? Try using <>, an copying it over to the same library folder as the standard headers. (Not a great solution, but a debugging approach to try.)

Why doesn’t iostream have a .h after it?

It’s been a decade since I used C…I don’t know the “using” keyword, but are you sure that semicolon is correct?

On further reflection, it seems to be telling you that “using” must be placed inside a function.

Have you eyeballed math.h? Look at the end of the file; does it look reasonable? Can you start another test project which uses math.h + as little else as possible to see whether it throws the same error? Have you any other projects which you know will compile which use math.h which you could try recompiling?

Huh… oddly enough, this code compiles fine and runs:

Puzzling… why would math.h compile in one, but not another, source?

Because every program needs a main().

My original program has a main().

For reference:

I’ve gotten it narrowed to 2 errors:

Neither of which are being thrown in ComplexNumberMain.cpp, but in ComplexNumber.cpp, instead. That is shown, abbreviated, below for anyone who might have any clue why math.h isn’t compiling correctly:

What’s in ComplexNumber.h? More to the point, what’s the last line of ComplexNumber.h end? (If it’s short, post the whole thing.)

First thing I’d do, seeing as you are using the “std” namespace, is replace "#include “math.h” " with “#include <cmath>” which is another (now) standard header. Then I’d check to make sure all the class declarations in your ComplexNumber.h are terminated with a semicolon:

class ComplexNumber { };

I always forget that semicolon.

Also, you shouldn’t have to include the implementation file (ComplexNumber.cpp) in your driver file, if you are using .NET. Simply including the header should work just fine.

Oh, yeah, and make sure you’ve got the header you wrote wrapped in the standard #ifndef#endif directives.

Algorithm,

You were on the head with the lost semicolon! However, adding it produced 9 new errors…

Looks like a conflict between the .h and .cpp…?

Again, I’m lost. sigh

Its been a bit since I did alot of C++, but it looks like you’re having a problem with something being included more than once- I would try removing the #include to your CPP file, and if that doesn’t work also try to make sure that you don’t #include something twice, even indirectly (ie #include <iostream> in one file, then #including both that file and iostream again in another file)

I’m betting ComplexNumber.h is getting included multiple times. The first two lines in every header (after whatever comments you include) should be (where COMPLEXNUMBER_H can be replaced with whatever):

#ifndef COMPLEXNUMBER_H
#define COMPLEXNUMBER_H

…and the last line of the header should be:

#endif

This ensures your header file will not get included multiple times. It looks like that is what’s happening here, as your driver includes both ComplexNumber.h and ComplexNumber.cpp, and the .cpp file also includes the .h.