# Visual Studio .NET Help Needed

**URL:** <https://boards.straightdope.com/t/visual-studio-net-help-needed/199683>\
**Category:** Factual Questions\
**Created:** [September 5, 2003, 7:13am UTC](https://boards.straightdope.com/t/visual-studio-net-help-needed/199683 "2003-09-05T07:13:59Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Civil\_Defense](https://avatars.discourse-cdn.com/v4/letter/c/ccd318/32.png) [@Civil\_Defense](https://boards.straightdope.com/u/Civil_Defense)\
**Post date:** [September 5, 2003, 7:13am UTC](https://boards.straightdope.com/t/visual-studio-net-help-needed/199683/1 "2003-09-05T07:13:59Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![EllisDee](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ellisdee/32/4531_2.png) [@EllisDee](https://boards.straightdope.com/u/EllisDee)\
**Post date:** [September 5, 2003, 8:07am UTC](https://boards.straightdope.com/t/visual-studio-net-help-needed/199683/2 "2003-09-05T08:07:27Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![EllisDee](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ellisdee/32/4531_2.png) [@EllisDee](https://boards.straightdope.com/u/EllisDee)\
**Post date:** [September 5, 2003, 8:08am UTC](https://boards.straightdope.com/t/visual-studio-net-help-needed/199683/3 "2003-09-05T08:08:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Xerxes](https://avatars.discourse-cdn.com/v4/letter/x/d2c977/32.png) [@Xerxes](https://boards.straightdope.com/u/Xerxes)\
**Post date:** [September 5, 2003, 8:13am UTC](https://boards.straightdope.com/t/visual-studio-net-help-needed/199683/4 "2003-09-05T08:13:37Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Civil\_Defense](https://avatars.discourse-cdn.com/v4/letter/c/ccd318/32.png) [@Civil\_Defense](https://boards.straightdope.com/u/Civil_Defense)\
**Post date:** [September 5, 2003, 8:19am UTC](https://boards.straightdope.com/t/visual-studio-net-help-needed/199683/5 "2003-09-05T08:19:03Z")

</div>

> [@](#):
>
> 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:

> [@](#):
>
> #include \<iostream\>  
> #include “math.h”
> 
> using namespace std;
> 
> void main() {  
> cout \<\< sin(3.0);  
> }

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

---

<div class="post-metadata">

**Author:** ![EllisDee](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ellisdee/32/4531_2.png) [@EllisDee](https://boards.straightdope.com/u/EllisDee)\
**Post date:** [September 5, 2003, 8:25am UTC](https://boards.straightdope.com/t/visual-studio-net-help-needed/199683/6 "2003-09-05T08:25:47Z")

</div>

Because every program needs a main().

---

<div class="post-metadata">

**Author:** ![Civil\_Defense](https://avatars.discourse-cdn.com/v4/letter/c/ccd318/32.png) [@Civil\_Defense](https://boards.straightdope.com/u/Civil_Defense)\
**Post date:** [September 5, 2003, 8:29am UTC](https://boards.straightdope.com/t/visual-studio-net-help-needed/199683/7 "2003-09-05T08:29:57Z")

</div>

> [@](#):
>
> Because every program needs a main().

My original program has a main().

For reference:

> [@](#):
>
> // ComplexNumberMain.cpp
> 
> #include \<iostream\>  
> #include “ComplexNumber.cpp”  
> #include “ComplexNumber.h”
> 
> using namespace std;
> 
> void displayMenu(int desc);  
> void createComplexNumber();  
> void editComplexNumber();  
> void displayComplexNumber();
> 
> ComplexNumber cn;  
> float r;  
> float theta;
> 
> void main() {  
> displayMenu(0);  
> return;  
> }

I’ve gotten it narrowed to 2 errors:

> [@](#):
>
> 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’

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:

> [@](#):
>
> #include \<iostream\>  
> #include “math.h”  
> #include “ComplexNumber.h”
> 
> using namespace std;
> 
> …

---

<div class="post-metadata">

**Author:** ![EllisDee](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ellisdee/32/4531_2.png) [@EllisDee](https://boards.straightdope.com/u/EllisDee)\
**Post date:** [September 5, 2003, 9:54am UTC](https://boards.straightdope.com/t/visual-studio-net-help-needed/199683/8 "2003-09-05T09:54:17Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![Algorithm](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/algorithm/32/12204_2.png) [@Algorithm](https://boards.straightdope.com/u/Algorithm)\
**Post date:** [September 5, 2003, 10:08am UTC](https://boards.straightdope.com/t/visual-studio-net-help-needed/199683/9 "2003-09-05T10:08:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Civil\_Defense](https://avatars.discourse-cdn.com/v4/letter/c/ccd318/32.png) [@Civil\_Defense](https://boards.straightdope.com/u/Civil_Defense)\
**Post date:** [September 5, 2003, 1:07pm UTC](https://boards.straightdope.com/t/visual-studio-net-help-needed/199683/10 "2003-09-05T13:07:04Z")

</div>

Algorithm,

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

> [@](#):
>
> ComplexNumber fatal error LNK1169: one or more multiply defined symbols found  
> ComplexNumber error LNK2005: “public: \_\_thiscall ComplexNumber::ComplexNumber(float,float)” (??0ComplexNumber@@QAE@MM@Z) already defined in ComplexNumber.obj  
> ComplexNumber error LNK2005: “public: \_\_thiscall ComplexNumber::ComplexNumber(void)” (??0ComplexNumber@@QAE@XZ) already defined in ComplexNumber.obj  
> ComplexNumber error LNK2005: "public: float \_\_thiscall ComplexNumber::getR(void)const " (?getR@ComplexNumber@@QBEMXZ) already defined in ComplexNumber.obj  
> ComplexNumber error LNK2005: "public: float \_\_thiscall ComplexNumber::getTheta(void)const " (?getTheta@ComplexNumber@@QBEMXZ) already defined in ComplexNumber.obj  
> ComplexNumber error LNK2005: “public: void \_\_thiscall ComplexNumber::displayCartesian(void)” (?displayCartesian@ComplexNumber@@QAEXXZ) already defined in ComplexNumber.obj  
> ComplexNumber error LNK2005: “public: void \_\_thiscall ComplexNumber::displayPolar(void)” (?displayPolar@ComplexNumber@@QAEXXZ) already defined in ComplexNumber.obj  
> ComplexNumber error LNK2005: “public: void \_\_thiscall ComplexNumber::setR(float)” (?setR@ComplexNumber@@QAEXM@Z) already defined in ComplexNumber.obj  
> ComplexNumber error LNK2005: “public: void \_\_thiscall ComplexNumber::setTheta(float)” (?setTheta@ComplexNumber@@QAEXM@Z) already defined in ComplexNumber.obj

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

Again, I’m lost. _sigh_

---

<div class="post-metadata">

**Author:** ![jacobsta](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@jacobsta](https://boards.straightdope.com/u/jacobsta)\
**Post date:** [September 5, 2003, 1:27pm UTC](https://boards.straightdope.com/t/visual-studio-net-help-needed/199683/11 "2003-09-05T13:27:15Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Algorithm](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/algorithm/32/12204_2.png) [@Algorithm](https://boards.straightdope.com/u/Algorithm)\
**Post date:** [September 5, 2003, 6:41pm UTC](https://boards.straightdope.com/t/visual-studio-net-help-needed/199683/12 "2003-09-05T18:41:50Z")

</div>

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.
