Weird Namespace error..

This is a discussion on Weird Namespace error.. within the C++ Programming forums, part of the General Programming Boards category; I've been getting this crazy namespace error when trying to compile a project, I've looked over the entire thing several ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    41

    Weird Namespace error..

    I've been getting this crazy namespace error when trying to compile a project, I've looked over the entire thing several times, even through the other files, and can't seem to fix it.

    Code:
    d:\C++\Vacuus_Beta\textNotrium.cpp(12) : error C2143: syntax error : missing ';' before 'using'
    main.cpp
    d:\C++\Vacuus_Beta\textNotrium.cpp(12) : error C2143: syntax error : missing ';' before 'using'
    The begining of the file, up to line 12:
    Code:
    #ifndef TEXTNOTRIUM_CPP
    #define TEXTNOTRIUM_CPP
    //Defines some common BAGE functions
    
    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <string.h>
    #include "engine.h" //For engine stuff;
    #include "engine_class.h"
    
    using namespace std;
    No doubt it's something simple that my poor mind can't pick up, but I'ld still appreciate any help.

    I use Visual C++ 2002.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,628
    textNotrium.cpp looks like a source file, but the header guard makes it look at a header file. Is it a header file or a source file? If it is a header file, you should not have the "using namespace std;" in at all.

    Anyway, my guess is that the problem could lie in "engine_class.h". What happens if you comment out the last two includes?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    41
    Commenting out the last 2 includes gives a heap of unidentifed errors, as textnotrium.cpp defines some (previously undefined) functions for classes included in engine.h (which, includes engine_class.h, amongst others)..

    In all honesty, I added the #ifndef line to see if it was in any way related to the problem.

    I'm just about to re-upload the entire source to this site again, which may help a little.

    Thanks.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,628
    Commenting out the last 2 includes gives a heap of unidentifed errors, as textnotrium.cpp defines some (previously undefined) functions for classes included in engine.h (which, includes engine_class.h, amongst others).
    The previous error you get (concerning using) is gone, right?

    By the way, you include "engine.h" in "textnotrium.cpp", but you say that "textnotrium.cpp defines ... included in engine.h"?

    EDIT:
    Look in engine.h
    Where is the terminating semi-colon for your gameObj class?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    Use <string> instead of <string.h>
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  6. #6
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Quote Originally Posted by Ideswa
    Use <string> instead of <string.h>
    Those are 2 different headers, if his works with string.h then the appropriate replacement is <cstring>

  7. #7
    Registered User
    Join Date
    May 2005
    Posts
    41
    Thanks for the help, everyone.

    Now, however, I get linker errors after changing all string.h includes to cstring, and adding that semicolon to the gameObj class..

    Code:
    textNotrium.obj : error LNK2005: "int __cdecl outputText_InColor(int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?outputText_InColor@@YAHHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in main.obj
    textNotrium.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl IntToString(int)" (?IntToString@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) already defined in main.obj
    textNotrium.obj : error LNK2005: "char __cdecl drawline(int)" (?drawline@@YADH@Z) already defined in main.obj
    textNotrium.obj : error LNK2005: "public: __thiscall prompt::prompt(int,int,int,class player *)" (??0prompt@@QAE@HHHPAVplayer@@@Z) already defined in main.obj
    textNotrium.obj : error LNK2005: "public: __thiscall player::player(void)" (??0player@@QAE@XZ) already defined in main.obj
    textNotrium.obj : error LNK2005: "public: __thiscall location::location(long,long,long)" (??0location@@QAE@JJJ@Z) already defined in main.obj
    textNotrium.obj : error LNK2005: "int __cdecl ReturnRand_InRange(int,int)" (?ReturnRand_InRange@@YAHHH@Z) already defined in main.obj
    textNotrium.obj : error LNK2005: "int __cdecl move(char,int,class player *)" (?move@@YAHDHPAVplayer@@@Z) already defined in main.obj
    textNotrium.obj : error LNK2005: "public: __thiscall iniFile::iniFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class prompt *)" (??0iniFile@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAVprompt@@@Z) already defined in main.obj
    textNotrium.obj : error LNK2005: "public: int __thiscall prompt::draw(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?draw@prompt@@QAEHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in main.obj
    textNotrium.obj : error LNK2005: "public: int __thiscall gameObj::gameLoop(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class prompt *)" (?gameLoop@gameObj@@QAEHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAVprompt@@@Z) already defined in main.obj
    textNotrium.obj : error LNK2005: "public: int __thiscall gameObj::BeginGame(class prompt *,class player *)" (?BeginGame@gameObj@@QAEHPAVprompt@@PAVplayer@@@Z) already defined in main.obj
    textNotrium.obj : error LNK2005: "public: bool __thiscall player::save(void)" (?save@player@@QAE_NXZ) already defined in main.obj
    textNotrium.obj : error LNK2005: "int __cdecl showmsg(class prompt *)" (?showmsg@@YAHPAVprompt@@@Z) already defined in main.obj
    textNotrium.obj : error LNK2005: "private: bool __thiscall iniFile::check(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int)" (?check@iniFile@@AAE_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) already defined in main.obj
    Debug/Vacuus_Beta.exe : fatal error LNK1169: one or more multiply defined symbols found
    In all honesty, these Linker errors really confuse me - any help would be greatly appreciated.

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> #include "textNotrium.cpp"
    Don't #include cpp files. This is your problem. Each cpp file is compiled, and so the functions defined in textNotrium.cpp are defined once when it is compiled, and defined again when main.cpp is compiled.

    >> #ifndef TEXTNOTRIUM_CPP
    Because you shouldn't #include cpp files, you don't need include guards for them. This won't really cause any errors, but there is no reason to have it there and you should understand why it is needed for the header files.

  9. #9
    Registered User
    Join Date
    May 2005
    Posts
    41
    You learn somethng new every day...
    Thanks for your explanation, Daved - it cut back the errors to 10, at which point I just changed the file to a header and added a guard.

    But now I'm having troubles with file I/O, in particular, reading a file.
    The program compiles, but whenever I run it, all I get is a prompt that refuses to progress any further, and doesn't seem to read the file.

    Here's the line called to intialize an ini file:
    Code:
    iniFile(".\\test.ini", &BasicPrompt);
    Class & constructor:
    http://bur.st/~vacuus/engine/engine_iniSystem.h

    Check function at the bottom of this file:
    http://bur.st/~vacuus/engine/textNotrium.h

    But, I appreciate all the help. Thanks again, everyone

  10. #10
    Registered User
    Join Date
    Oct 2005
    Posts
    271
    If it is a header file, you should not have the "using namespace std;" in at all.
    Hmm, interesting. Is it something that's in, like, rock? Because if it is, the program I'm working on will have a sewage treatment facilty's worth of crap.

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> Is it something that's in, like, rock?
    No. For beginner programs its not that big of a deal. The bigger your project gets, though, the more likely it is to cause a problem, and it is generally better to form the good habits to start with.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 03:09 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 04:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21